Merge master.kernel.org:/pub/scm/linux/kernel/git/perex/alsa

* master.kernel.org:/pub/scm/linux/kernel/git/perex/alsa: (28 commits)
[ALSA] Kconfig SND_SEQUENCER_OSS help text fix
[ALSA] Add Aux input switch control for Aureon Universe
[ALSA] pcxhr - Fix the crash with REV01 board
[ALSA] sound/pci/hda: use create_singlethread_workqueue()
[ALSA] hda-intel - Add support of ATI SB600
[ALSA] cs4281 - Fix the check of timeout in probe
[ALSA] cs4281 - Fix the check of right channel
[ALSA] Test volume resolution of usb audio at initialization
[ALSA] maestro3.c: fix BUG, optimization
[ALSA] HDA/Realtek: multiple input mux definitions and pin mode additions
[ALSA] AdLib FM card driver
[ALSA] Fix / clean up PCM-OSS setup hooks
[ALSA] Clean up PCM codes (take 2)
[ALSA] Tiny clean up of PCM codes
[ALSA] ISA drivers bailing on first !enable[i]
[ALSA] Remove obsolete kfree_nocheck call
[ALSA] Remove obsolete kfree_nocheck call
[ALSA] Add snd-als300 driver for Avance Logic ALS300/ALS300+ soundcards
[ALSA] Add snd-riptide driver for Conexant Riptide chip
[ALSA] hda-codec - Fix noisy output wtih AD1986A 3stack model
...

+5660 -474
+69
Documentation/sound/alsa/ALSA-Configuration.txt
··· 120 enable - enable card 121 - Default: enabled, for PCI and ISA PnP cards 122 123 Module snd-ad1816a 124 ------------------ 125 ··· 215 fm_port - port # for OPL3 FM (PnP setup) 216 217 This module supports multiple cards, autoprobe and PnP. 218 219 The power-management is supported. 220 ··· 738 uniwill 3-jack 739 F1734 2-jack 740 lg LG laptop (m1 express dual) 741 test for testing/debugging purpose, almost all controls can be 742 adjusted. Appearing only when compiled with 743 $CONFIG_SND_DEBUG=y ··· 1051 1052 The power-management is supported. 1053 1054 Module snd-mixart 1055 ----------------- 1056 ··· 1256 For ARM architecture only. 1257 1258 The power-management is supported. 1259 1260 Module snd-rme32 1261 ----------------
··· 120 enable - enable card 121 - Default: enabled, for PCI and ISA PnP cards 122 123 + Module snd-adlib 124 + ---------------- 125 + 126 + Module for AdLib FM cards. 127 + 128 + port - port # for OPL chip 129 + 130 + This module supports multiple cards. It does not support autoprobe, so 131 + the port must be specified. For actual AdLib FM cards it will be 0x388. 132 + Note that this card does not have PCM support and no mixer; only FM 133 + synthesis. 134 + 135 + Make sure you have "sbiload" from the alsa-tools package available and, 136 + after loading the module, find out the assigned ALSA sequencer port 137 + number through "sbiload -l". Example output: 138 + 139 + Port Client name Port name 140 + 64:0 OPL2 FM synth OPL2 FM Port 141 + 142 + Load the std.sb and drums.sb patches also supplied by sbiload: 143 + 144 + sbiload -p 64:0 std.sb drums.sb 145 + 146 + If you use this driver to drive an OPL3, you can use std.o3 and drums.o3 147 + instead. To have the card produce sound, use aplaymidi from alsa-utils: 148 + 149 + aplaymidi -p 64:0 foo.mid 150 + 151 Module snd-ad1816a 152 ------------------ 153 ··· 187 fm_port - port # for OPL3 FM (PnP setup) 188 189 This module supports multiple cards, autoprobe and PnP. 190 + 191 + The power-management is supported. 192 + 193 + Module snd-als300 194 + ----------------- 195 + 196 + Module for Avance Logic ALS300 and ALS300+ 197 + 198 + This module supports multiple cards. 199 200 The power-management is supported. 201 ··· 701 uniwill 3-jack 702 F1734 2-jack 703 lg LG laptop (m1 express dual) 704 + lg-lw LG LW20 laptop 705 test for testing/debugging purpose, almost all controls can be 706 adjusted. Appearing only when compiled with 707 $CONFIG_SND_DEBUG=y ··· 1013 1014 The power-management is supported. 1015 1016 + Module snd-miro 1017 + --------------- 1018 + 1019 + Module for Miro soundcards: miroSOUND PCM 1 pro, 1020 + miroSOUND PCM 12, 1021 + miroSOUND PCM 20 Radio. 1022 + 1023 + port - Port # (0x530,0x604,0xe80,0xf40) 1024 + irq - IRQ # (5,7,9,10,11) 1025 + dma1 - 1st dma # (0,1,3) 1026 + dma2 - 2nd dma # (0,1) 1027 + mpu_port - MPU-401 port # (0x300,0x310,0x320,0x330) 1028 + mpu_irq - MPU-401 irq # (5,7,9,10) 1029 + fm_port - FM Port # (0x388) 1030 + wss - enable WSS mode 1031 + ide - enable onboard ide support 1032 + 1033 Module snd-mixart 1034 ----------------- 1035 ··· 1201 For ARM architecture only. 1202 1203 The power-management is supported. 1204 + 1205 + Module snd-riptide 1206 + ------------------ 1207 + 1208 + Module for Conexant Riptide chip 1209 + 1210 + joystick_port - Joystick port # (default: 0x200) 1211 + mpu_port - MPU401 port # (default: 0x330) 1212 + opl3_port - OPL3 port # (default: 0x388) 1213 + 1214 + This module supports multiple cards. 1215 + The driver requires the firmware loader support on kernel. 1216 + You need to install the firmware file "riptide.hex" to the standard 1217 + firmware path (e.g. /lib/firmware). 1218 1219 Module snd-rme32 1220 ----------------
+1 -1
include/sound/core.h
··· 170 } 171 172 /* init.c */ 173 - int snd_power_wait(struct snd_card *card, unsigned int power_state, struct file *file); 174 175 #else /* ! CONFIG_PM */ 176
··· 170 } 171 172 /* init.c */ 173 + int snd_power_wait(struct snd_card *card, unsigned int power_state); 174 175 #else /* ! CONFIG_PM */ 176
+7 -8
include/sound/pcm.h
··· 369 /* -- assigned files -- */ 370 struct snd_pcm_file *file; 371 struct file *ffile; 372 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 373 /* -- OSS things -- */ 374 struct snd_pcm_oss_substream oss; ··· 382 struct snd_info_entry *proc_prealloc_entry; 383 /* misc flags */ 384 unsigned int no_mmap_ctrl: 1; 385 }; 386 387 - #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 388 - #define SUBSTREAM_BUSY(substream) ((substream)->file != NULL || ((substream)->oss.file != NULL)) 389 - #else 390 #define SUBSTREAM_BUSY(substream) ((substream)->file != NULL) 391 - #endif 392 393 394 struct snd_pcm_str { ··· 458 struct snd_pcm_info __user *info); 459 int snd_pcm_status(struct snd_pcm_substream *substream, 460 struct snd_pcm_status *status); 461 - int snd_pcm_prepare(struct snd_pcm_substream *substream); 462 int snd_pcm_start(struct snd_pcm_substream *substream); 463 int snd_pcm_stop(struct snd_pcm_substream *substream, int status); 464 int snd_pcm_drain_done(struct snd_pcm_substream *substream); ··· 465 int snd_pcm_suspend(struct snd_pcm_substream *substream); 466 int snd_pcm_suspend_all(struct snd_pcm *pcm); 467 #endif 468 - int snd_pcm_kernel_playback_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg); 469 - int snd_pcm_kernel_capture_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg); 470 int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg); 471 - int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct snd_pcm_substream **rsubstream); 472 void snd_pcm_release_substream(struct snd_pcm_substream *substream); 473 void snd_pcm_vma_notify_data(void *client, void *data); 474 int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area); 475
··· 369 /* -- assigned files -- */ 370 struct snd_pcm_file *file; 371 struct file *ffile; 372 + void (*pcm_release)(struct snd_pcm_substream *); 373 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 374 /* -- OSS things -- */ 375 struct snd_pcm_oss_substream oss; ··· 381 struct snd_info_entry *proc_prealloc_entry; 382 /* misc flags */ 383 unsigned int no_mmap_ctrl: 1; 384 + unsigned int hw_opened: 1; 385 }; 386 387 #define SUBSTREAM_BUSY(substream) ((substream)->file != NULL) 388 389 390 struct snd_pcm_str { ··· 460 struct snd_pcm_info __user *info); 461 int snd_pcm_status(struct snd_pcm_substream *substream, 462 struct snd_pcm_status *status); 463 int snd_pcm_start(struct snd_pcm_substream *substream); 464 int snd_pcm_stop(struct snd_pcm_substream *substream, int status); 465 int snd_pcm_drain_done(struct snd_pcm_substream *substream); ··· 468 int snd_pcm_suspend(struct snd_pcm_substream *substream); 469 int snd_pcm_suspend_all(struct snd_pcm *pcm); 470 #endif 471 int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg); 472 + int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file, 473 + struct snd_pcm_substream **rsubstream); 474 void snd_pcm_release_substream(struct snd_pcm_substream *substream); 475 + int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file, 476 + struct snd_pcm_substream **rsubstream); 477 + void snd_pcm_detach_substream(struct snd_pcm_substream *substream); 478 void snd_pcm_vma_notify_data(void *client, void *data); 479 int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area); 480
+1 -2
include/sound/pcm_oss.h
··· 69 70 struct snd_pcm_oss_substream { 71 unsigned oss: 1; /* oss mode */ 72 - struct snd_pcm_oss_setup *setup; /* active setup */ 73 - struct snd_pcm_oss_file *file; 74 }; 75 76 struct snd_pcm_oss_stream {
··· 69 70 struct snd_pcm_oss_substream { 71 unsigned oss: 1; /* oss mode */ 72 + struct snd_pcm_oss_setup setup; /* active setup */ 73 }; 74 75 struct snd_pcm_oss_stream {
+3 -2
sound/core/Kconfig
··· 92 93 Many programs still use the OSS API, so say Y. 94 95 - To compile this driver as a module, choose M here: the module 96 - will be called snd-seq-oss. 97 98 config SND_RTCTIMER 99 tristate "RTC Timer support"
··· 92 93 Many programs still use the OSS API, so say Y. 94 95 + If you choose M in "Sequencer support" (SND_SEQUENCER), 96 + this will be compiled as a module. The module will be called 97 + snd-seq-oss. 98 99 config SND_RTCTIMER 100 tristate "RTC Timer support"
+3 -3
sound/core/control.c
··· 664 if (copy_from_user(&info, _info, sizeof(info))) 665 return -EFAULT; 666 snd_power_lock(ctl->card); 667 - result = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0, NULL); 668 if (result >= 0) 669 result = snd_ctl_elem_info(ctl, &info); 670 snd_power_unlock(ctl->card); ··· 718 return -EFAULT; 719 } 720 snd_power_lock(card); 721 - result = snd_power_wait(card, SNDRV_CTL_POWER_D0, NULL); 722 if (result >= 0) 723 result = snd_ctl_elem_read(card, control); 724 snd_power_unlock(card); ··· 783 } 784 card = file->card; 785 snd_power_lock(card); 786 - result = snd_power_wait(card, SNDRV_CTL_POWER_D0, NULL); 787 if (result >= 0) 788 result = snd_ctl_elem_write(card, file, control); 789 snd_power_unlock(card);
··· 664 if (copy_from_user(&info, _info, sizeof(info))) 665 return -EFAULT; 666 snd_power_lock(ctl->card); 667 + result = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0); 668 if (result >= 0) 669 result = snd_ctl_elem_info(ctl, &info); 670 snd_power_unlock(ctl->card); ··· 718 return -EFAULT; 719 } 720 snd_power_lock(card); 721 + result = snd_power_wait(card, SNDRV_CTL_POWER_D0); 722 if (result >= 0) 723 result = snd_ctl_elem_read(card, control); 724 snd_power_unlock(card); ··· 783 } 784 card = file->card; 785 snd_power_lock(card); 786 + result = snd_power_wait(card, SNDRV_CTL_POWER_D0); 787 if (result >= 0) 788 result = snd_ctl_elem_write(card, file, control); 789 snd_power_unlock(card);
+3 -3
sound/core/control_compat.c
··· 109 goto error; 110 111 snd_power_lock(ctl->card); 112 - err = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0, NULL); 113 if (err >= 0) 114 err = snd_ctl_elem_info(ctl, data); 115 snd_power_unlock(ctl->card); ··· 294 goto error; 295 296 snd_power_lock(card); 297 - err = snd_power_wait(card, SNDRV_CTL_POWER_D0, NULL); 298 if (err >= 0) 299 err = snd_ctl_elem_read(card, data); 300 snd_power_unlock(card); ··· 320 goto error; 321 322 snd_power_lock(card); 323 - err = snd_power_wait(card, SNDRV_CTL_POWER_D0, NULL); 324 if (err >= 0) 325 err = snd_ctl_elem_write(card, file, data); 326 snd_power_unlock(card);
··· 109 goto error; 110 111 snd_power_lock(ctl->card); 112 + err = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0); 113 if (err >= 0) 114 err = snd_ctl_elem_info(ctl, data); 115 snd_power_unlock(ctl->card); ··· 294 goto error; 295 296 snd_power_lock(card); 297 + err = snd_power_wait(card, SNDRV_CTL_POWER_D0); 298 if (err >= 0) 299 err = snd_ctl_elem_read(card, data); 300 snd_power_unlock(card); ··· 320 goto error; 321 322 snd_power_lock(card); 323 + err = snd_power_wait(card, SNDRV_CTL_POWER_D0); 324 if (err >= 0) 325 err = snd_ctl_elem_write(card, file, data); 326 snd_power_unlock(card);
+1 -8
sound/core/init.c
··· 722 * snd_power_wait - wait until the power-state is changed. 723 * @card: soundcard structure 724 * @power_state: expected power state 725 - * @file: file structure for the O_NONBLOCK check (optional) 726 * 727 * Waits until the power-state is changed. 728 * 729 * Note: the power lock must be active before call. 730 */ 731 - int snd_power_wait(struct snd_card *card, unsigned int power_state, struct file *file) 732 { 733 wait_queue_t wait; 734 int result = 0; ··· 744 } 745 if (snd_power_get_state(card) == power_state) 746 break; 747 - #if 0 /* block all devices */ 748 - if (file && (file->f_flags & O_NONBLOCK)) { 749 - result = -EAGAIN; 750 - break; 751 - } 752 - #endif 753 set_current_state(TASK_UNINTERRUPTIBLE); 754 snd_power_unlock(card); 755 schedule_timeout(30 * HZ);
··· 722 * snd_power_wait - wait until the power-state is changed. 723 * @card: soundcard structure 724 * @power_state: expected power state 725 * 726 * Waits until the power-state is changed. 727 * 728 * Note: the power lock must be active before call. 729 */ 730 + int snd_power_wait(struct snd_card *card, unsigned int power_state) 731 { 732 wait_queue_t wait; 733 int result = 0; ··· 745 } 746 if (snd_power_get_state(card) == power_state) 747 break; 748 set_current_state(TASK_UNINTERRUPTIBLE); 749 snd_power_unlock(card); 750 schedule_timeout(30 * HZ);
+109 -179
sound/core/oss/pcm_oss.c
··· 208 oss_buffer_size = runtime->oss.mmap_bytes; 209 } 210 211 - if (substream->oss.setup && 212 - substream->oss.setup->period_size > 16) 213 - oss_period_size = substream->oss.setup->period_size; 214 else if (runtime->oss.fragshift) { 215 oss_period_size = 1 << runtime->oss.fragshift; 216 if (oss_period_size > oss_buffer_size / 2) ··· 251 252 oss_periods = oss_buffer_size / oss_period_size; 253 254 - if (substream->oss.setup) { 255 - if (substream->oss.setup->periods > 1) 256 - oss_periods = substream->oss.setup->periods; 257 - } 258 259 s = snd_pcm_hw_param_value_max(slave_params, SNDRV_PCM_HW_PARAM_PERIODS, NULL); 260 if (runtime->oss.maxfrags && s > runtime->oss.maxfrags) ··· 338 goto failure; 339 } 340 341 - if (atomic_read(&runtime->mmap_count)) { 342 direct = 1; 343 - } else { 344 - struct snd_pcm_oss_setup *setup = substream->oss.setup; 345 - direct = (setup != NULL && setup->direct); 346 - } 347 348 _snd_pcm_hw_params_any(sparams); 349 _snd_pcm_hw_param_setinteger(sparams, SNDRV_PCM_HW_PARAM_PERIODS); ··· 477 1 : runtime->period_size; 478 sw_params->xfer_align = 1; 479 if (atomic_read(&runtime->mmap_count) || 480 - (substream->oss.setup && substream->oss.setup->nosilence)) { 481 sw_params->silence_threshold = 0; 482 sw_params->silence_size = 0; 483 } else { ··· 838 buf += tmp; 839 bytes -= tmp; 840 xfer += tmp; 841 - if ((substream->oss.setup != NULL && substream->oss.setup->partialfrag) || 842 runtime->oss.buffer_used == runtime->oss.period_bytes) { 843 tmp = snd_pcm_oss_write2(substream, runtime->oss.buffer + runtime->oss.period_ptr, 844 runtime->oss.buffer_used - runtime->oss.period_ptr, 1); ··· 954 955 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK]; 956 if (substream != NULL) { 957 - snd_pcm_kernel_playback_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); 958 substream->runtime->oss.prepare = 1; 959 } 960 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE]; 961 if (substream != NULL) { 962 - snd_pcm_kernel_capture_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); 963 substream->runtime->oss.prepare = 1; 964 } 965 return 0; ··· 974 if (substream != NULL) { 975 if ((err = snd_pcm_oss_make_ready(substream)) < 0) 976 return err; 977 - snd_pcm_kernel_playback_ioctl(substream, SNDRV_PCM_IOCTL_START, NULL); 978 } 979 /* note: all errors from the start action are ignored */ 980 /* OSS apps do not know, how to handle them */ ··· 1103 __direct: 1104 saved_f_flags = substream->ffile->f_flags; 1105 substream->ffile->f_flags &= ~O_NONBLOCK; 1106 - err = snd_pcm_kernel_playback_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL); 1107 substream->ffile->f_flags = saved_f_flags; 1108 if (err < 0) 1109 return err; ··· 1115 if ((err = snd_pcm_oss_make_ready(substream)) < 0) 1116 return err; 1117 runtime = substream->runtime; 1118 - err = snd_pcm_kernel_capture_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); 1119 if (err < 0) 1120 return err; 1121 runtime->oss.buffer_used = 0; ··· 1209 1210 if ((err = snd_pcm_oss_get_active_substream(pcm_oss_file, &substream)) < 0) 1211 return err; 1212 - if (atomic_read(&substream->runtime->mmap_count)) { 1213 direct = 1; 1214 - } else { 1215 - struct snd_pcm_oss_setup *setup = substream->oss.setup; 1216 - direct = (setup != NULL && setup->direct); 1217 - } 1218 if (!direct) 1219 return AFMT_MU_LAW | AFMT_U8 | 1220 AFMT_S16_LE | AFMT_S16_BE | ··· 1430 cmd = SNDRV_PCM_IOCTL_DROP; 1431 runtime->oss.prepare = 1; 1432 } 1433 - err = snd_pcm_kernel_playback_ioctl(psubstream, cmd, NULL); 1434 if (err < 0) 1435 return err; 1436 } ··· 1451 cmd = SNDRV_PCM_IOCTL_DROP; 1452 runtime->oss.prepare = 1; 1453 } 1454 - err = snd_pcm_kernel_capture_ioctl(csubstream, cmd, NULL); 1455 if (err < 0) 1456 return err; 1457 } ··· 1488 runtime = substream->runtime; 1489 if (runtime->oss.params || runtime->oss.prepare) 1490 return 0; 1491 - err = snd_pcm_kernel_playback_ioctl(substream, SNDRV_PCM_IOCTL_DELAY, &delay); 1492 if (err == -EPIPE) 1493 delay = 0; /* hack for broken OSS applications */ 1494 else if (err < 0) ··· 1548 } else { 1549 delay = snd_pcm_oss_bytes(substream, delay); 1550 if (stream == SNDRV_PCM_STREAM_PLAYBACK) { 1551 - struct snd_pcm_oss_setup *setup = substream->oss.setup; 1552 - if (setup && setup->buggyptr) 1553 info.blocks = (runtime->oss.buffer_bytes - delay - fixup) / runtime->oss.period_bytes; 1554 else 1555 info.blocks = (delay + fixup) / runtime->oss.period_bytes; ··· 1630 return -EINVAL; 1631 } 1632 1633 - static struct snd_pcm_oss_setup *snd_pcm_oss_look_for_setup(struct snd_pcm *pcm, int stream, const char *task_name) 1634 { 1635 - const char *ptr, *ptrl; 1636 struct snd_pcm_oss_setup *setup; 1637 1638 mutex_lock(&pcm->streams[stream].oss.setup_mutex); 1639 - for (setup = pcm->streams[stream].oss.setup_list; setup; setup = setup->next) { 1640 - if (!strcmp(setup->task_name, task_name)) { 1641 - mutex_unlock(&pcm->streams[stream].oss.setup_mutex); 1642 - return setup; 1643 } 1644 - } 1645 - ptr = ptrl = task_name; 1646 - while (*ptr) { 1647 - if (*ptr == '/') 1648 - ptrl = ptr + 1; 1649 - ptr++; 1650 - } 1651 - if (ptrl == task_name) { 1652 - goto __not_found; 1653 - return NULL; 1654 - } 1655 - for (setup = pcm->streams[stream].oss.setup_list; setup; setup = setup->next) { 1656 - if (!strcmp(setup->task_name, ptrl)) { 1657 - mutex_unlock(&pcm->streams[stream].oss.setup_mutex); 1658 - return setup; 1659 - } 1660 - } 1661 - __not_found: 1662 mutex_unlock(&pcm->streams[stream].oss.setup_mutex); 1663 - return NULL; 1664 } 1665 1666 static void snd_pcm_oss_init_substream(struct snd_pcm_substream *substream, ··· 1679 struct snd_pcm_runtime *runtime; 1680 1681 substream->oss.oss = 1; 1682 - substream->oss.setup = setup; 1683 runtime = substream->runtime; 1684 runtime->oss.params = 1; 1685 runtime->oss.trigger = 1; ··· 1702 runtime->oss.fragshift = 0; 1703 runtime->oss.maxfrags = 0; 1704 runtime->oss.subdivision = 0; 1705 - } 1706 - 1707 - static void snd_pcm_oss_release_substream(struct snd_pcm_substream *substream) 1708 - { 1709 - struct snd_pcm_runtime *runtime; 1710 - runtime = substream->runtime; 1711 - vfree(runtime->oss.buffer); 1712 - #ifdef CONFIG_SND_PCM_OSS_PLUGINS 1713 - snd_pcm_oss_plugin_clear(substream); 1714 - #endif 1715 - substream->oss.file = NULL; 1716 - substream->oss.oss = 0; 1717 } 1718 1719 static int snd_pcm_oss_release_file(struct snd_pcm_oss_file *pcm_oss_file) ··· 1711 snd_assert(pcm_oss_file != NULL, return -ENXIO); 1712 for (cidx = 0; cidx < 2; ++cidx) { 1713 struct snd_pcm_substream *substream = pcm_oss_file->streams[cidx]; 1714 - struct snd_pcm_runtime *runtime; 1715 - if (substream == NULL) 1716 - continue; 1717 - runtime = substream->runtime; 1718 - 1719 - snd_pcm_stream_lock_irq(substream); 1720 - if (snd_pcm_running(substream)) 1721 - snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); 1722 - snd_pcm_stream_unlock_irq(substream); 1723 - if (substream->ffile != NULL) { 1724 - if (substream->ops->hw_free != NULL) 1725 - substream->ops->hw_free(substream); 1726 - substream->ops->close(substream); 1727 - substream->ffile = NULL; 1728 - } 1729 - snd_pcm_oss_release_substream(substream); 1730 - snd_pcm_release_substream(substream); 1731 } 1732 kfree(pcm_oss_file); 1733 return 0; ··· 1722 struct snd_pcm *pcm, 1723 struct snd_pcm_oss_file **rpcm_oss_file, 1724 int minor, 1725 - struct snd_pcm_oss_setup *psetup, 1726 - struct snd_pcm_oss_setup *csetup) 1727 { 1728 - int err = 0; 1729 struct snd_pcm_oss_file *pcm_oss_file; 1730 - struct snd_pcm_substream *psubstream = NULL, *csubstream = NULL; 1731 unsigned int f_mode = file->f_mode; 1732 1733 snd_assert(rpcm_oss_file != NULL, return -EINVAL); ··· 1739 if ((f_mode & (FMODE_WRITE|FMODE_READ)) == (FMODE_WRITE|FMODE_READ) && 1740 (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX)) 1741 f_mode = FMODE_WRITE; 1742 - if ((f_mode & FMODE_WRITE) && !(psetup && psetup->disable)) { 1743 - if ((err = snd_pcm_open_substream(pcm, SNDRV_PCM_STREAM_PLAYBACK, 1744 - &psubstream)) < 0) { 1745 snd_pcm_oss_release_file(pcm_oss_file); 1746 return err; 1747 } 1748 - pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK] = psubstream; 1749 - } 1750 - if ((f_mode & FMODE_READ) && !(csetup && csetup->disable)) { 1751 - if ((err = snd_pcm_open_substream(pcm, SNDRV_PCM_STREAM_CAPTURE, 1752 - &csubstream)) < 0) { 1753 - if (!(f_mode & FMODE_WRITE) || err != -ENODEV) { 1754 - snd_pcm_oss_release_file(pcm_oss_file); 1755 - return err; 1756 - } else { 1757 - csubstream = NULL; 1758 - } 1759 - } 1760 - pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE] = csubstream; 1761 } 1762 1763 - if (psubstream == NULL && csubstream == NULL) { 1764 snd_pcm_oss_release_file(pcm_oss_file); 1765 return -EINVAL; 1766 - } 1767 - if (psubstream != NULL) { 1768 - psubstream->oss.file = pcm_oss_file; 1769 - err = snd_pcm_hw_constraints_init(psubstream); 1770 - if (err < 0) { 1771 - snd_printd("snd_pcm_hw_constraint_init failed\n"); 1772 - snd_pcm_oss_release_file(pcm_oss_file); 1773 - return err; 1774 - } 1775 - if ((err = psubstream->ops->open(psubstream)) < 0) { 1776 - snd_pcm_oss_release_file(pcm_oss_file); 1777 - return err; 1778 - } 1779 - psubstream->ffile = file; 1780 - err = snd_pcm_hw_constraints_complete(psubstream); 1781 - if (err < 0) { 1782 - snd_printd("snd_pcm_hw_constraint_complete failed\n"); 1783 - snd_pcm_oss_release_file(pcm_oss_file); 1784 - return err; 1785 - } 1786 - snd_pcm_oss_init_substream(psubstream, psetup, minor); 1787 - } 1788 - if (csubstream != NULL) { 1789 - csubstream->oss.file = pcm_oss_file; 1790 - err = snd_pcm_hw_constraints_init(csubstream); 1791 - if (err < 0) { 1792 - snd_printd("snd_pcm_hw_constraint_init failed\n"); 1793 - snd_pcm_oss_release_file(pcm_oss_file); 1794 - return err; 1795 - } 1796 - if ((err = csubstream->ops->open(csubstream)) < 0) { 1797 - snd_pcm_oss_release_file(pcm_oss_file); 1798 - return err; 1799 - } 1800 - csubstream->ffile = file; 1801 - err = snd_pcm_hw_constraints_complete(csubstream); 1802 - if (err < 0) { 1803 - snd_printd("snd_pcm_hw_constraint_complete failed\n"); 1804 - snd_pcm_oss_release_file(pcm_oss_file); 1805 - return err; 1806 - } 1807 - snd_pcm_oss_init_substream(csubstream, csetup, minor); 1808 } 1809 1810 file->private_data = pcm_oss_file; ··· 1788 char task_name[32]; 1789 struct snd_pcm *pcm; 1790 struct snd_pcm_oss_file *pcm_oss_file; 1791 - struct snd_pcm_oss_setup *psetup = NULL, *csetup = NULL; 1792 int nonblock; 1793 wait_queue_t wait; 1794 ··· 1809 err = -EFAULT; 1810 goto __error; 1811 } 1812 if (file->f_mode & FMODE_WRITE) 1813 - psetup = snd_pcm_oss_look_for_setup(pcm, SNDRV_PCM_STREAM_PLAYBACK, task_name); 1814 if (file->f_mode & FMODE_READ) 1815 - csetup = snd_pcm_oss_look_for_setup(pcm, SNDRV_PCM_STREAM_CAPTURE, task_name); 1816 1817 nonblock = !!(file->f_flags & O_NONBLOCK); 1818 - if (psetup && !psetup->disable) { 1819 - if (psetup->nonblock) 1820 - nonblock = 1; 1821 - else if (psetup->block) 1822 - nonblock = 0; 1823 - } else if (csetup && !csetup->disable) { 1824 - if (csetup->nonblock) 1825 - nonblock = 1; 1826 - else if (csetup->block) 1827 - nonblock = 0; 1828 - } 1829 if (!nonblock) 1830 nonblock = nonblock_open; 1831 ··· 1826 mutex_lock(&pcm->open_mutex); 1827 while (1) { 1828 err = snd_pcm_oss_open_file(file, pcm, &pcm_oss_file, 1829 - iminor(inode), psetup, csetup); 1830 if (err >= 0) 1831 break; 1832 if (err == -EAGAIN) { ··· 2240 2241 static void snd_pcm_oss_proc_free_setup_list(struct snd_pcm_str * pstr) 2242 { 2243 - unsigned int idx; 2244 - struct snd_pcm_substream *substream; 2245 struct snd_pcm_oss_setup *setup, *setupn; 2246 2247 - for (idx = 0, substream = pstr->substream; 2248 - idx < pstr->substream_count; idx++, substream = substream->next) 2249 - substream->oss.setup = NULL; 2250 for (setup = pstr->oss.setup_list, pstr->oss.setup_list = NULL; 2251 setup; setup = setupn) { 2252 setupn = setup->next; ··· 2302 } 2303 } while (*str); 2304 if (setup == NULL) { 2305 - setup = kmalloc(sizeof(struct snd_pcm_oss_setup), GFP_KERNEL); 2306 - if (setup) { 2307 - if (pstr->oss.setup_list == NULL) { 2308 - pstr->oss.setup_list = setup; 2309 - } else { 2310 - for (setup1 = pstr->oss.setup_list; setup1->next; setup1 = setup1->next); 2311 - setup1->next = setup; 2312 - } 2313 - template.task_name = kstrdup(task_name, GFP_KERNEL); 2314 - } else { 2315 buffer->error = -ENOMEM; 2316 } 2317 } 2318 - if (setup) 2319 - *setup = template; 2320 mutex_unlock(&pstr->oss.setup_mutex); 2321 } 2322 }
··· 208 oss_buffer_size = runtime->oss.mmap_bytes; 209 } 210 211 + if (substream->oss.setup.period_size > 16) 212 + oss_period_size = substream->oss.setup.period_size; 213 else if (runtime->oss.fragshift) { 214 oss_period_size = 1 << runtime->oss.fragshift; 215 if (oss_period_size > oss_buffer_size / 2) ··· 252 253 oss_periods = oss_buffer_size / oss_period_size; 254 255 + if (substream->oss.setup.periods > 1) 256 + oss_periods = substream->oss.setup.periods; 257 258 s = snd_pcm_hw_param_value_max(slave_params, SNDRV_PCM_HW_PARAM_PERIODS, NULL); 259 if (runtime->oss.maxfrags && s > runtime->oss.maxfrags) ··· 341 goto failure; 342 } 343 344 + if (atomic_read(&runtime->mmap_count)) 345 direct = 1; 346 + else 347 + direct = substream->oss.setup.direct; 348 349 _snd_pcm_hw_params_any(sparams); 350 _snd_pcm_hw_param_setinteger(sparams, SNDRV_PCM_HW_PARAM_PERIODS); ··· 482 1 : runtime->period_size; 483 sw_params->xfer_align = 1; 484 if (atomic_read(&runtime->mmap_count) || 485 + substream->oss.setup.nosilence) { 486 sw_params->silence_threshold = 0; 487 sw_params->silence_size = 0; 488 } else { ··· 843 buf += tmp; 844 bytes -= tmp; 845 xfer += tmp; 846 + if (substream->oss.setup.partialfrag || 847 runtime->oss.buffer_used == runtime->oss.period_bytes) { 848 tmp = snd_pcm_oss_write2(substream, runtime->oss.buffer + runtime->oss.period_ptr, 849 runtime->oss.buffer_used - runtime->oss.period_ptr, 1); ··· 959 960 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK]; 961 if (substream != NULL) { 962 + snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); 963 substream->runtime->oss.prepare = 1; 964 } 965 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE]; 966 if (substream != NULL) { 967 + snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); 968 substream->runtime->oss.prepare = 1; 969 } 970 return 0; ··· 979 if (substream != NULL) { 980 if ((err = snd_pcm_oss_make_ready(substream)) < 0) 981 return err; 982 + snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_START, NULL); 983 } 984 /* note: all errors from the start action are ignored */ 985 /* OSS apps do not know, how to handle them */ ··· 1108 __direct: 1109 saved_f_flags = substream->ffile->f_flags; 1110 substream->ffile->f_flags &= ~O_NONBLOCK; 1111 + err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL); 1112 substream->ffile->f_flags = saved_f_flags; 1113 if (err < 0) 1114 return err; ··· 1120 if ((err = snd_pcm_oss_make_ready(substream)) < 0) 1121 return err; 1122 runtime = substream->runtime; 1123 + err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); 1124 if (err < 0) 1125 return err; 1126 runtime->oss.buffer_used = 0; ··· 1214 1215 if ((err = snd_pcm_oss_get_active_substream(pcm_oss_file, &substream)) < 0) 1216 return err; 1217 + if (atomic_read(&substream->runtime->mmap_count)) 1218 direct = 1; 1219 + else 1220 + direct = substream->oss.setup.direct; 1221 if (!direct) 1222 return AFMT_MU_LAW | AFMT_U8 | 1223 AFMT_S16_LE | AFMT_S16_BE | ··· 1437 cmd = SNDRV_PCM_IOCTL_DROP; 1438 runtime->oss.prepare = 1; 1439 } 1440 + err = snd_pcm_kernel_ioctl(psubstream, cmd, NULL); 1441 if (err < 0) 1442 return err; 1443 } ··· 1458 cmd = SNDRV_PCM_IOCTL_DROP; 1459 runtime->oss.prepare = 1; 1460 } 1461 + err = snd_pcm_kernel_ioctl(csubstream, cmd, NULL); 1462 if (err < 0) 1463 return err; 1464 } ··· 1495 runtime = substream->runtime; 1496 if (runtime->oss.params || runtime->oss.prepare) 1497 return 0; 1498 + err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DELAY, &delay); 1499 if (err == -EPIPE) 1500 delay = 0; /* hack for broken OSS applications */ 1501 else if (err < 0) ··· 1555 } else { 1556 delay = snd_pcm_oss_bytes(substream, delay); 1557 if (stream == SNDRV_PCM_STREAM_PLAYBACK) { 1558 + if (substream->oss.setup.buggyptr) 1559 info.blocks = (runtime->oss.buffer_bytes - delay - fixup) / runtime->oss.period_bytes; 1560 else 1561 info.blocks = (delay + fixup) / runtime->oss.period_bytes; ··· 1638 return -EINVAL; 1639 } 1640 1641 + static const char *strip_task_path(const char *path) 1642 { 1643 + const char *ptr, *ptrl = NULL; 1644 + for (ptr = path; *ptr; ptr++) { 1645 + if (*ptr == '/') 1646 + ptrl = ptr + 1; 1647 + } 1648 + return ptrl; 1649 + } 1650 + 1651 + static void snd_pcm_oss_look_for_setup(struct snd_pcm *pcm, int stream, 1652 + const char *task_name, 1653 + struct snd_pcm_oss_setup *rsetup) 1654 + { 1655 struct snd_pcm_oss_setup *setup; 1656 1657 mutex_lock(&pcm->streams[stream].oss.setup_mutex); 1658 + do { 1659 + for (setup = pcm->streams[stream].oss.setup_list; setup; 1660 + setup = setup->next) { 1661 + if (!strcmp(setup->task_name, task_name)) 1662 + goto out; 1663 } 1664 + } while ((task_name = strip_task_path(task_name)) != NULL); 1665 + out: 1666 + if (setup) 1667 + *rsetup = *setup; 1668 mutex_unlock(&pcm->streams[stream].oss.setup_mutex); 1669 + } 1670 + 1671 + static void snd_pcm_oss_release_substream(struct snd_pcm_substream *substream) 1672 + { 1673 + struct snd_pcm_runtime *runtime; 1674 + runtime = substream->runtime; 1675 + vfree(runtime->oss.buffer); 1676 + runtime->oss.buffer = NULL; 1677 + #ifdef CONFIG_SND_PCM_OSS_PLUGINS 1678 + snd_pcm_oss_plugin_clear(substream); 1679 + #endif 1680 + substream->oss.oss = 0; 1681 } 1682 1683 static void snd_pcm_oss_init_substream(struct snd_pcm_substream *substream, ··· 1678 struct snd_pcm_runtime *runtime; 1679 1680 substream->oss.oss = 1; 1681 + substream->oss.setup = *setup; 1682 + if (setup->nonblock) 1683 + substream->ffile->f_flags |= O_NONBLOCK; 1684 + else 1685 + substream->ffile->f_flags &= ~O_NONBLOCK; 1686 runtime = substream->runtime; 1687 runtime->oss.params = 1; 1688 runtime->oss.trigger = 1; ··· 1697 runtime->oss.fragshift = 0; 1698 runtime->oss.maxfrags = 0; 1699 runtime->oss.subdivision = 0; 1700 + substream->pcm_release = snd_pcm_oss_release_substream; 1701 } 1702 1703 static int snd_pcm_oss_release_file(struct snd_pcm_oss_file *pcm_oss_file) ··· 1717 snd_assert(pcm_oss_file != NULL, return -ENXIO); 1718 for (cidx = 0; cidx < 2; ++cidx) { 1719 struct snd_pcm_substream *substream = pcm_oss_file->streams[cidx]; 1720 + if (substream) 1721 + snd_pcm_release_substream(substream); 1722 } 1723 kfree(pcm_oss_file); 1724 return 0; ··· 1743 struct snd_pcm *pcm, 1744 struct snd_pcm_oss_file **rpcm_oss_file, 1745 int minor, 1746 + struct snd_pcm_oss_setup *setup) 1747 { 1748 + int idx, err; 1749 struct snd_pcm_oss_file *pcm_oss_file; 1750 + struct snd_pcm_substream *substream; 1751 unsigned int f_mode = file->f_mode; 1752 1753 snd_assert(rpcm_oss_file != NULL, return -EINVAL); ··· 1761 if ((f_mode & (FMODE_WRITE|FMODE_READ)) == (FMODE_WRITE|FMODE_READ) && 1762 (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX)) 1763 f_mode = FMODE_WRITE; 1764 + 1765 + for (idx = 0; idx < 2; idx++) { 1766 + if (setup[idx].disable) 1767 + continue; 1768 + if (idx == SNDRV_PCM_STREAM_PLAYBACK) { 1769 + if (! (f_mode & FMODE_WRITE)) 1770 + continue; 1771 + } else { 1772 + if (! (f_mode & FMODE_READ)) 1773 + continue; 1774 + } 1775 + err = snd_pcm_open_substream(pcm, idx, file, &substream); 1776 + if (err < 0) { 1777 snd_pcm_oss_release_file(pcm_oss_file); 1778 return err; 1779 } 1780 + 1781 + pcm_oss_file->streams[idx] = substream; 1782 + snd_pcm_oss_init_substream(substream, &setup[idx], minor); 1783 } 1784 1785 + if (! pcm_oss_file->streams[0] && pcm_oss_file->streams[1]) { 1786 snd_pcm_oss_release_file(pcm_oss_file); 1787 return -EINVAL; 1788 } 1789 1790 file->private_data = pcm_oss_file; ··· 1852 char task_name[32]; 1853 struct snd_pcm *pcm; 1854 struct snd_pcm_oss_file *pcm_oss_file; 1855 + struct snd_pcm_oss_setup setup[2]; 1856 int nonblock; 1857 wait_queue_t wait; 1858 ··· 1873 err = -EFAULT; 1874 goto __error; 1875 } 1876 + memset(setup, 0, sizeof(*setup)); 1877 if (file->f_mode & FMODE_WRITE) 1878 + snd_pcm_oss_look_for_setup(pcm, SNDRV_PCM_STREAM_PLAYBACK, 1879 + task_name, &setup[0]); 1880 if (file->f_mode & FMODE_READ) 1881 + snd_pcm_oss_look_for_setup(pcm, SNDRV_PCM_STREAM_CAPTURE, 1882 + task_name, &setup[1]); 1883 1884 nonblock = !!(file->f_flags & O_NONBLOCK); 1885 if (!nonblock) 1886 nonblock = nonblock_open; 1887 ··· 1898 mutex_lock(&pcm->open_mutex); 1899 while (1) { 1900 err = snd_pcm_oss_open_file(file, pcm, &pcm_oss_file, 1901 + iminor(inode), setup); 1902 if (err >= 0) 1903 break; 1904 if (err == -EAGAIN) { ··· 2312 2313 static void snd_pcm_oss_proc_free_setup_list(struct snd_pcm_str * pstr) 2314 { 2315 struct snd_pcm_oss_setup *setup, *setupn; 2316 2317 for (setup = pstr->oss.setup_list, pstr->oss.setup_list = NULL; 2318 setup; setup = setupn) { 2319 setupn = setup->next; ··· 2379 } 2380 } while (*str); 2381 if (setup == NULL) { 2382 + setup = kmalloc(sizeof(*setup), GFP_KERNEL); 2383 + if (! setup) { 2384 buffer->error = -ENOMEM; 2385 + mutex_lock(&pstr->oss.setup_mutex); 2386 + return; 2387 + } 2388 + if (pstr->oss.setup_list == NULL) 2389 + pstr->oss.setup_list = setup; 2390 + else { 2391 + for (setup1 = pstr->oss.setup_list; 2392 + setup1->next; setup1 = setup1->next); 2393 + setup1->next = setup; 2394 + } 2395 + template.task_name = kstrdup(task_name, GFP_KERNEL); 2396 + if (! template.task_name) { 2397 + kfree(setup); 2398 + buffer->error = -ENOMEM; 2399 + mutex_lock(&pstr->oss.setup_mutex); 2400 + return; 2401 } 2402 } 2403 + *setup = template; 2404 mutex_unlock(&pstr->oss.setup_mutex); 2405 } 2406 }
+6 -8
sound/core/pcm.c
··· 777 snd_pcm_tick_elapsed(substream); 778 } 779 780 - int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, 781 - struct snd_pcm_substream **rsubstream) 782 { 783 struct snd_pcm_str * pstr; 784 struct snd_pcm_substream *substream; ··· 794 *rsubstream = NULL; 795 snd_assert(pcm != NULL, return -ENXIO); 796 pstr = &pcm->streams[stream]; 797 - if (pstr->substream == NULL) 798 return -ENODEV; 799 800 card = pcm->card; ··· 808 } 809 up_read(&card->controls_rwsem); 810 811 - if (pstr->substream_count == 0) 812 - return -ENODEV; 813 switch (stream) { 814 case SNDRV_PCM_STREAM_PLAYBACK: 815 if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) { ··· 873 874 substream->runtime = runtime; 875 substream->private_data = pcm->private_data; 876 pstr->substream_opened++; 877 *rsubstream = substream; 878 return 0; 879 } 880 881 - void snd_pcm_release_substream(struct snd_pcm_substream *substream) 882 { 883 struct snd_pcm_runtime *runtime; 884 substream->file = NULL; ··· 1111 EXPORT_SYMBOL(snd_pcm_suspend); 1112 EXPORT_SYMBOL(snd_pcm_suspend_all); 1113 #endif 1114 - EXPORT_SYMBOL(snd_pcm_kernel_playback_ioctl); 1115 - EXPORT_SYMBOL(snd_pcm_kernel_capture_ioctl); 1116 EXPORT_SYMBOL(snd_pcm_kernel_ioctl); 1117 EXPORT_SYMBOL(snd_pcm_mmap_data); 1118 #if SNDRV_PCM_INFO_MMAP_IOMEM
··· 777 snd_pcm_tick_elapsed(substream); 778 } 779 780 + int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, 781 + struct file *file, 782 + struct snd_pcm_substream **rsubstream) 783 { 784 struct snd_pcm_str * pstr; 785 struct snd_pcm_substream *substream; ··· 793 *rsubstream = NULL; 794 snd_assert(pcm != NULL, return -ENXIO); 795 pstr = &pcm->streams[stream]; 796 + if (pstr->substream == NULL || pstr->substream_count == 0) 797 return -ENODEV; 798 799 card = pcm->card; ··· 807 } 808 up_read(&card->controls_rwsem); 809 810 switch (stream) { 811 case SNDRV_PCM_STREAM_PLAYBACK: 812 if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) { ··· 874 875 substream->runtime = runtime; 876 substream->private_data = pcm->private_data; 877 + substream->ffile = file; 878 pstr->substream_opened++; 879 *rsubstream = substream; 880 return 0; 881 } 882 883 + void snd_pcm_detach_substream(struct snd_pcm_substream *substream) 884 { 885 struct snd_pcm_runtime *runtime; 886 substream->file = NULL; ··· 1111 EXPORT_SYMBOL(snd_pcm_suspend); 1112 EXPORT_SYMBOL(snd_pcm_suspend_all); 1113 #endif 1114 EXPORT_SYMBOL(snd_pcm_kernel_ioctl); 1115 EXPORT_SYMBOL(snd_pcm_mmap_data); 1116 #if SNDRV_PCM_INFO_MMAP_IOMEM
-49
sound/core/pcm_lib.c
··· 2299 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) 2300 return -EBADFD; 2301 2302 - snd_assert(substream->ffile != NULL, return -ENXIO); 2303 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK); 2304 - #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 2305 - if (substream->oss.oss) { 2306 - struct snd_pcm_oss_setup *setup = substream->oss.setup; 2307 - if (setup != NULL) { 2308 - if (setup->nonblock) 2309 - nonblock = 1; 2310 - else if (setup->block) 2311 - nonblock = 0; 2312 - } 2313 - } 2314 - #endif 2315 2316 if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED && 2317 runtime->channels > 1) ··· 2362 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) 2363 return -EBADFD; 2364 2365 - snd_assert(substream->ffile != NULL, return -ENXIO); 2366 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK); 2367 - #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 2368 - if (substream->oss.oss) { 2369 - struct snd_pcm_oss_setup *setup = substream->oss.setup; 2370 - if (setup != NULL) { 2371 - if (setup->nonblock) 2372 - nonblock = 1; 2373 - else if (setup->block) 2374 - nonblock = 0; 2375 - } 2376 - } 2377 - #endif 2378 2379 if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) 2380 return -EINVAL; ··· 2572 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) 2573 return -EBADFD; 2574 2575 - snd_assert(substream->ffile != NULL, return -ENXIO); 2576 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK); 2577 - #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 2578 - if (substream->oss.oss) { 2579 - struct snd_pcm_oss_setup *setup = substream->oss.setup; 2580 - if (setup != NULL) { 2581 - if (setup->nonblock) 2582 - nonblock = 1; 2583 - else if (setup->block) 2584 - nonblock = 0; 2585 - } 2586 - } 2587 - #endif 2588 if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED) 2589 return -EINVAL; 2590 return snd_pcm_lib_read1(substream, (unsigned long)buf, size, nonblock, snd_pcm_lib_read_transfer); ··· 2629 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) 2630 return -EBADFD; 2631 2632 - snd_assert(substream->ffile != NULL, return -ENXIO); 2633 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK); 2634 - #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) 2635 - if (substream->oss.oss) { 2636 - struct snd_pcm_oss_setup *setup = substream->oss.setup; 2637 - if (setup != NULL) { 2638 - if (setup->nonblock) 2639 - nonblock = 1; 2640 - else if (setup->block) 2641 - nonblock = 0; 2642 - } 2643 - } 2644 - #endif 2645 - 2646 if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) 2647 return -EINVAL; 2648 return snd_pcm_lib_read1(substream, (unsigned long)bufs, frames, nonblock, snd_pcm_lib_readv_transfer);
··· 2299 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) 2300 return -EBADFD; 2301 2302 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK); 2303 2304 if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED && 2305 runtime->channels > 1) ··· 2374 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) 2375 return -EBADFD; 2376 2377 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK); 2378 2379 if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) 2380 return -EINVAL; ··· 2596 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) 2597 return -EBADFD; 2598 2599 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK); 2600 if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED) 2601 return -EINVAL; 2602 return snd_pcm_lib_read1(substream, (unsigned long)buf, size, nonblock, snd_pcm_lib_read_transfer); ··· 2665 if (runtime->status->state == SNDRV_PCM_STATE_OPEN) 2666 return -EBADFD; 2667 2668 nonblock = !!(substream->ffile->f_flags & O_NONBLOCK); 2669 if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) 2670 return -EINVAL; 2671 return snd_pcm_lib_read1(substream, (unsigned long)bufs, frames, nonblock, snd_pcm_lib_readv_transfer);
+77 -84
sound/core/pcm_native.c
··· 1170 int res; 1171 1172 snd_power_lock(card); 1173 - if ((res = snd_power_wait(card, SNDRV_CTL_POWER_D0, substream->ffile)) >= 0) 1174 res = snd_pcm_action_lock_irq(&snd_pcm_action_resume, substream, 0); 1175 snd_power_unlock(card); 1176 return res; ··· 1198 1199 snd_power_lock(card); 1200 if (runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1201 - result = snd_power_wait(card, SNDRV_CTL_POWER_D0, substream->ffile); 1202 if (result < 0) 1203 goto _unlock; 1204 } ··· 1313 * 1314 * Prepare the PCM substream to be triggerable. 1315 */ 1316 - int snd_pcm_prepare(struct snd_pcm_substream *substream) 1317 { 1318 int res; 1319 struct snd_card *card = substream->pcm->card; 1320 1321 snd_power_lock(card); 1322 - if ((res = snd_power_wait(card, SNDRV_CTL_POWER_D0, substream->ffile)) >= 0) 1323 res = snd_pcm_action_nonatomic(&snd_pcm_action_prepare, substream, 0); 1324 snd_power_unlock(card); 1325 return res; ··· 1410 1411 snd_power_lock(card); 1412 if (runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1413 - result = snd_power_wait(card, SNDRV_CTL_POWER_D0, substream->ffile); 1414 if (result < 0) { 1415 snd_power_unlock(card); 1416 return result; ··· 1533 1534 snd_power_lock(card); 1535 if (runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1536 - result = snd_power_wait(card, SNDRV_CTL_POWER_D0, substream->ffile); 1537 if (result < 0) 1538 goto _unlock; 1539 } ··· 1995 } 1996 } 1997 1998 - static int snd_pcm_release_file(struct snd_pcm_file * pcm_file) 1999 { 2000 - struct snd_pcm_substream *substream; 2001 - struct snd_pcm_runtime *runtime; 2002 - struct snd_pcm_str * str; 2003 2004 - snd_assert(pcm_file != NULL, return -ENXIO); 2005 - substream = pcm_file->substream; 2006 - snd_assert(substream != NULL, return -ENXIO); 2007 - runtime = substream->runtime; 2008 - str = substream->pstr; 2009 snd_pcm_unlink(substream); 2010 - if (substream->ffile != NULL) { 2011 if (substream->ops->hw_free != NULL) 2012 substream->ops->hw_free(substream); 2013 substream->ops->close(substream); 2014 - substream->ffile = NULL; 2015 } 2016 - snd_pcm_remove_file(str, pcm_file); 2017 - snd_pcm_release_substream(substream); 2018 - kfree(pcm_file); 2019 return 0; 2020 } 2021 2022 static int snd_pcm_open_file(struct file *file, ··· 2059 int stream, 2060 struct snd_pcm_file **rpcm_file) 2061 { 2062 - int err = 0; 2063 struct snd_pcm_file *pcm_file; 2064 struct snd_pcm_substream *substream; 2065 struct snd_pcm_str *str; 2066 2067 snd_assert(rpcm_file != NULL, return -EINVAL); 2068 *rpcm_file = NULL; 2069 2070 pcm_file = kzalloc(sizeof(*pcm_file), GFP_KERNEL); 2071 if (pcm_file == NULL) { 2072 return -ENOMEM; 2073 } 2074 - 2075 - if ((err = snd_pcm_open_substream(pcm, stream, &substream)) < 0) { 2076 - kfree(pcm_file); 2077 - return err; 2078 - } 2079 - 2080 str = substream->pstr; 2081 substream->file = pcm_file; 2082 - substream->no_mmap_ctrl = 0; 2083 - 2084 pcm_file->substream = substream; 2085 - 2086 snd_pcm_add_file(str, pcm_file); 2087 - 2088 - err = snd_pcm_hw_constraints_init(substream); 2089 - if (err < 0) { 2090 - snd_printd("snd_pcm_hw_constraints_init failed\n"); 2091 - snd_pcm_release_file(pcm_file); 2092 - return err; 2093 - } 2094 - 2095 - if ((err = substream->ops->open(substream)) < 0) { 2096 - snd_pcm_release_file(pcm_file); 2097 - return err; 2098 - } 2099 - substream->ffile = file; 2100 - 2101 - err = snd_pcm_hw_constraints_complete(substream); 2102 - if (err < 0) { 2103 - snd_printd("snd_pcm_hw_constraints_complete failed\n"); 2104 - snd_pcm_release_file(pcm_file); 2105 - return err; 2106 - } 2107 2108 file->private_data = pcm_file; 2109 *rpcm_file = pcm_file; ··· 2170 snd_assert(substream != NULL, return -ENXIO); 2171 snd_assert(!atomic_read(&substream->runtime->mmap_count), ); 2172 pcm = substream->pcm; 2173 - snd_pcm_drop(substream); 2174 fasync_helper(-1, file, 0, &substream->runtime->fasync); 2175 mutex_lock(&pcm->open_mutex); 2176 - snd_pcm_release_file(pcm_file); 2177 mutex_unlock(&pcm->open_mutex); 2178 wake_up(&pcm->open_wait); 2179 module_put(pcm->card->module); ··· 2491 return 0; 2492 } 2493 2494 - static int snd_pcm_playback_ioctl1(struct snd_pcm_substream *substream, 2495 - unsigned int cmd, void __user *arg); 2496 - static int snd_pcm_capture_ioctl1(struct snd_pcm_substream *substream, 2497 - unsigned int cmd, void __user *arg); 2498 - 2499 static int snd_pcm_common_ioctl1(struct snd_pcm_substream *substream, 2500 unsigned int cmd, void __user *arg) 2501 { ··· 2742 return snd_pcm_capture_ioctl1(pcm_file->substream, cmd, (void __user *)arg); 2743 } 2744 2745 - int snd_pcm_kernel_playback_ioctl(struct snd_pcm_substream *substream, 2746 - unsigned int cmd, void *arg) 2747 - { 2748 - mm_segment_t fs; 2749 - int result; 2750 - 2751 - fs = snd_enter_user(); 2752 - result = snd_pcm_playback_ioctl1(substream, cmd, (void __user *)arg); 2753 - snd_leave_user(fs); 2754 - return result; 2755 - } 2756 - 2757 - int snd_pcm_kernel_capture_ioctl(struct snd_pcm_substream *substream, 2758 - unsigned int cmd, void *arg) 2759 - { 2760 - mm_segment_t fs; 2761 - int result; 2762 - 2763 - fs = snd_enter_user(); 2764 - result = snd_pcm_capture_ioctl1(substream, cmd, (void __user *)arg); 2765 - snd_leave_user(fs); 2766 - return result; 2767 - } 2768 - 2769 int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, 2770 unsigned int cmd, void *arg) 2771 { 2772 switch (substream->stream) { 2773 case SNDRV_PCM_STREAM_PLAYBACK: 2774 - return snd_pcm_kernel_playback_ioctl(substream, cmd, arg); 2775 case SNDRV_PCM_STREAM_CAPTURE: 2776 - return snd_pcm_kernel_capture_ioctl(substream, cmd, arg); 2777 default: 2778 - return -EINVAL; 2779 } 2780 } 2781 2782 static ssize_t snd_pcm_read(struct file *file, char __user *buf, size_t count,
··· 1170 int res; 1171 1172 snd_power_lock(card); 1173 + if ((res = snd_power_wait(card, SNDRV_CTL_POWER_D0)) >= 0) 1174 res = snd_pcm_action_lock_irq(&snd_pcm_action_resume, substream, 0); 1175 snd_power_unlock(card); 1176 return res; ··· 1198 1199 snd_power_lock(card); 1200 if (runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1201 + result = snd_power_wait(card, SNDRV_CTL_POWER_D0); 1202 if (result < 0) 1203 goto _unlock; 1204 } ··· 1313 * 1314 * Prepare the PCM substream to be triggerable. 1315 */ 1316 + static int snd_pcm_prepare(struct snd_pcm_substream *substream) 1317 { 1318 int res; 1319 struct snd_card *card = substream->pcm->card; 1320 1321 snd_power_lock(card); 1322 + if ((res = snd_power_wait(card, SNDRV_CTL_POWER_D0)) >= 0) 1323 res = snd_pcm_action_nonatomic(&snd_pcm_action_prepare, substream, 0); 1324 snd_power_unlock(card); 1325 return res; ··· 1410 1411 snd_power_lock(card); 1412 if (runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1413 + result = snd_power_wait(card, SNDRV_CTL_POWER_D0); 1414 if (result < 0) { 1415 snd_power_unlock(card); 1416 return result; ··· 1533 1534 snd_power_lock(card); 1535 if (runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1536 + result = snd_power_wait(card, SNDRV_CTL_POWER_D0); 1537 if (result < 0) 1538 goto _unlock; 1539 } ··· 1995 } 1996 } 1997 1998 + static void pcm_release_private(struct snd_pcm_substream *substream) 1999 { 2000 + struct snd_pcm_file *pcm_file = substream->file; 2001 2002 snd_pcm_unlink(substream); 2003 + snd_pcm_remove_file(substream->pstr, pcm_file); 2004 + kfree(pcm_file); 2005 + } 2006 + 2007 + void snd_pcm_release_substream(struct snd_pcm_substream *substream) 2008 + { 2009 + snd_pcm_drop(substream); 2010 + if (substream->pcm_release) 2011 + substream->pcm_release(substream); 2012 + if (substream->hw_opened) { 2013 if (substream->ops->hw_free != NULL) 2014 substream->ops->hw_free(substream); 2015 substream->ops->close(substream); 2016 + substream->hw_opened = 0; 2017 } 2018 + snd_pcm_detach_substream(substream); 2019 + } 2020 + 2021 + int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, 2022 + struct file *file, 2023 + struct snd_pcm_substream **rsubstream) 2024 + { 2025 + struct snd_pcm_substream *substream; 2026 + int err; 2027 + 2028 + err = snd_pcm_attach_substream(pcm, stream, file, &substream); 2029 + if (err < 0) 2030 + return err; 2031 + substream->no_mmap_ctrl = 0; 2032 + err = snd_pcm_hw_constraints_init(substream); 2033 + if (err < 0) { 2034 + snd_printd("snd_pcm_hw_constraints_init failed\n"); 2035 + goto error; 2036 + } 2037 + 2038 + if ((err = substream->ops->open(substream)) < 0) 2039 + goto error; 2040 + 2041 + substream->hw_opened = 1; 2042 + 2043 + err = snd_pcm_hw_constraints_complete(substream); 2044 + if (err < 0) { 2045 + snd_printd("snd_pcm_hw_constraints_complete failed\n"); 2046 + goto error; 2047 + } 2048 + 2049 + *rsubstream = substream; 2050 return 0; 2051 + 2052 + error: 2053 + snd_pcm_release_substream(substream); 2054 + return err; 2055 } 2056 2057 static int snd_pcm_open_file(struct file *file, ··· 2024 int stream, 2025 struct snd_pcm_file **rpcm_file) 2026 { 2027 struct snd_pcm_file *pcm_file; 2028 struct snd_pcm_substream *substream; 2029 struct snd_pcm_str *str; 2030 + int err; 2031 2032 snd_assert(rpcm_file != NULL, return -EINVAL); 2033 *rpcm_file = NULL; 2034 2035 + err = snd_pcm_open_substream(pcm, stream, file, &substream); 2036 + if (err < 0) 2037 + return err; 2038 + 2039 pcm_file = kzalloc(sizeof(*pcm_file), GFP_KERNEL); 2040 if (pcm_file == NULL) { 2041 + snd_pcm_release_substream(substream); 2042 return -ENOMEM; 2043 } 2044 str = substream->pstr; 2045 substream->file = pcm_file; 2046 + substream->pcm_release = pcm_release_private; 2047 pcm_file->substream = substream; 2048 snd_pcm_add_file(str, pcm_file); 2049 2050 file->private_data = pcm_file; 2051 *rpcm_file = pcm_file; ··· 2158 snd_assert(substream != NULL, return -ENXIO); 2159 snd_assert(!atomic_read(&substream->runtime->mmap_count), ); 2160 pcm = substream->pcm; 2161 fasync_helper(-1, file, 0, &substream->runtime->fasync); 2162 mutex_lock(&pcm->open_mutex); 2163 + snd_pcm_release_substream(substream); 2164 mutex_unlock(&pcm->open_mutex); 2165 wake_up(&pcm->open_wait); 2166 module_put(pcm->card->module); ··· 2480 return 0; 2481 } 2482 2483 static int snd_pcm_common_ioctl1(struct snd_pcm_substream *substream, 2484 unsigned int cmd, void __user *arg) 2485 { ··· 2736 return snd_pcm_capture_ioctl1(pcm_file->substream, cmd, (void __user *)arg); 2737 } 2738 2739 int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, 2740 unsigned int cmd, void *arg) 2741 { 2742 + mm_segment_t fs; 2743 + int result; 2744 + 2745 + fs = snd_enter_user(); 2746 switch (substream->stream) { 2747 case SNDRV_PCM_STREAM_PLAYBACK: 2748 + result = snd_pcm_playback_ioctl1(substream, 2749 + cmd, (void __user *)arg); 2750 + break; 2751 case SNDRV_PCM_STREAM_CAPTURE: 2752 + result = snd_pcm_capture_ioctl1(substream, 2753 + cmd, (void __user *)arg); 2754 + break; 2755 default: 2756 + result = -EINVAL; 2757 + break; 2758 } 2759 + snd_leave_user(fs); 2760 + return result; 2761 } 2762 2763 static ssize_t snd_pcm_read(struct file *file, char __user *buf, size_t count,
+23
sound/isa/Kconfig
··· 11 tristate 12 select SND_PCM 13 14 config SND_AD1816A 15 tristate "Analog Devices SoundPort AD1816A" 16 depends on SND && PNP && ISA ··· 300 301 To compile this driver as a module, choose M here: the module 302 will be called snd-opti93x. 303 304 config SND_SB8 305 tristate "Sound Blaster 1.0/2.0/Pro (8-bit)"
··· 11 tristate 12 select SND_PCM 13 14 + config SND_ADLIB 15 + tristate "AdLib FM card" 16 + select SND_OPL3_LIB 17 + help 18 + Say Y here to include support for AdLib FM cards. 19 + 20 + To compile this driver as a module, choose M here: the module 21 + will be called snd-adlib. 22 + 23 config SND_AD1816A 24 tristate "Analog Devices SoundPort AD1816A" 25 depends on SND && PNP && ISA ··· 291 292 To compile this driver as a module, choose M here: the module 293 will be called snd-opti93x. 294 + 295 + config SND_MIRO 296 + tristate "Miro miroSOUND PCM1pro/PCM12/PCM20radio driver" 297 + depends on SND 298 + select SND_OPL4_LIB 299 + select SND_CS4231_LIB 300 + select SND_MPU401_UART 301 + select SND_PCM 302 + help 303 + Say 'Y' or 'M' to include support for Miro miroSOUND PCM1 pro, 304 + miroSOUND PCM12 and miroSOUND PCM20 Radio soundcards. 305 + 306 + To compile this driver as a module, choose M here: the module 307 + will be called snd-miro. 308 309 config SND_SB8 310 tristate "Sound Blaster 1.0/2.0/Pro (8-bit)"
+2
sound/isa/Makefile
··· 3 # Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz> 4 # 5 6 snd-als100-objs := als100.o 7 snd-azt2320-objs := azt2320.o 8 snd-cmi8330-objs := cmi8330.o ··· 14 snd-sscape-objs := sscape.o 15 16 # Toplevel Module Dependency 17 obj-$(CONFIG_SND_ALS100) += snd-als100.o 18 obj-$(CONFIG_SND_AZT2320) += snd-azt2320.o 19 obj-$(CONFIG_SND_CMI8330) += snd-cmi8330.o
··· 3 # Copyright (c) 2001 by Jaroslav Kysela <perex@suse.cz> 4 # 5 6 + snd-adlib-objs := adlib.o 7 snd-als100-objs := als100.o 8 snd-azt2320-objs := azt2320.o 9 snd-cmi8330-objs := cmi8330.o ··· 13 snd-sscape-objs := sscape.o 14 15 # Toplevel Module Dependency 16 + obj-$(CONFIG_SND_ADLIB) += snd-adlib.o 17 obj-$(CONFIG_SND_ALS100) += snd-als100.o 18 obj-$(CONFIG_SND_AZT2320) += snd-azt2320.o 19 obj-$(CONFIG_SND_CMI8330) += snd-cmi8330.o
+161
sound/isa/adlib.c
···
··· 1 + /* 2 + * AdLib FM card driver. 3 + */ 4 + 5 + #include <sound/driver.h> 6 + #include <linux/kernel.h> 7 + #include <linux/module.h> 8 + #include <linux/platform_device.h> 9 + #include <sound/core.h> 10 + #include <sound/initval.h> 11 + #include <sound/opl3.h> 12 + 13 + #define CRD_NAME "AdLib FM" 14 + #define DRV_NAME "snd_adlib" 15 + 16 + MODULE_DESCRIPTION(CRD_NAME); 17 + MODULE_AUTHOR("Rene Herman"); 18 + MODULE_LICENSE("GPL"); 19 + 20 + static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 21 + static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 22 + static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; 23 + static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; 24 + 25 + module_param_array(index, int, NULL, 0444); 26 + MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); 27 + module_param_array(id, charp, NULL, 0444); 28 + MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); 29 + module_param_array(enable, bool, NULL, 0444); 30 + MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); 31 + module_param_array(port, long, NULL, 0444); 32 + MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); 33 + 34 + static struct platform_device *devices[SNDRV_CARDS]; 35 + 36 + static void snd_adlib_free(struct snd_card *card) 37 + { 38 + release_and_free_resource(card->private_data); 39 + } 40 + 41 + static int __devinit snd_adlib_probe(struct platform_device *device) 42 + { 43 + struct snd_card *card; 44 + struct snd_opl3 *opl3; 45 + 46 + int error; 47 + int i = device->id; 48 + 49 + if (port[i] == SNDRV_AUTO_PORT) { 50 + snd_printk(KERN_ERR DRV_NAME ": please specify port\n"); 51 + error = -EINVAL; 52 + goto out0; 53 + } 54 + 55 + card = snd_card_new(index[i], id[i], THIS_MODULE, 0); 56 + if (!card) { 57 + snd_printk(KERN_ERR DRV_NAME ": could not create card\n"); 58 + error = -EINVAL; 59 + goto out0; 60 + } 61 + 62 + card->private_data = request_region(port[i], 4, CRD_NAME); 63 + if (!card->private_data) { 64 + snd_printk(KERN_ERR DRV_NAME ": could not grab ports\n"); 65 + error = -EBUSY; 66 + goto out1; 67 + } 68 + card->private_free = snd_adlib_free; 69 + 70 + error = snd_opl3_create(card, port[i], port[i] + 2, OPL3_HW_AUTO, 1, &opl3); 71 + if (error < 0) { 72 + snd_printk(KERN_ERR DRV_NAME ": could not create OPL\n"); 73 + goto out1; 74 + } 75 + 76 + error = snd_opl3_hwdep_new(opl3, 0, 0, NULL); 77 + if (error < 0) { 78 + snd_printk(KERN_ERR DRV_NAME ": could not create FM\n"); 79 + goto out1; 80 + } 81 + 82 + strcpy(card->driver, DRV_NAME); 83 + strcpy(card->shortname, CRD_NAME); 84 + sprintf(card->longname, CRD_NAME " at %#lx", port[i]); 85 + 86 + snd_card_set_dev(card, &device->dev); 87 + 88 + error = snd_card_register(card); 89 + if (error < 0) { 90 + snd_printk(KERN_ERR DRV_NAME ": could not register card\n"); 91 + goto out1; 92 + } 93 + 94 + platform_set_drvdata(device, card); 95 + return 0; 96 + 97 + out1: snd_card_free(card); 98 + out0: error = -EINVAL; /* FIXME: should be the original error code */ 99 + return error; 100 + } 101 + 102 + static int __devexit snd_adlib_remove(struct platform_device *device) 103 + { 104 + snd_card_free(platform_get_drvdata(device)); 105 + platform_set_drvdata(device, NULL); 106 + return 0; 107 + } 108 + 109 + static struct platform_driver snd_adlib_driver = { 110 + .probe = snd_adlib_probe, 111 + .remove = __devexit_p(snd_adlib_remove), 112 + 113 + .driver = { 114 + .name = DRV_NAME 115 + } 116 + }; 117 + 118 + static int __init alsa_card_adlib_init(void) 119 + { 120 + int i, cards; 121 + 122 + if (platform_driver_register(&snd_adlib_driver) < 0) { 123 + snd_printk(KERN_ERR DRV_NAME ": could not register driver\n"); 124 + return -ENODEV; 125 + } 126 + 127 + for (cards = 0, i = 0; i < SNDRV_CARDS; i++) { 128 + struct platform_device *device; 129 + 130 + if (!enable[i]) 131 + continue; 132 + 133 + device = platform_device_register_simple(DRV_NAME, i, NULL, 0); 134 + if (IS_ERR(device)) 135 + continue; 136 + 137 + devices[i] = device; 138 + cards++; 139 + } 140 + 141 + if (!cards) { 142 + #ifdef MODULE 143 + printk(KERN_ERR CRD_NAME " soundcard not found or device busy\n"); 144 + #endif 145 + platform_driver_unregister(&snd_adlib_driver); 146 + return -ENODEV; 147 + } 148 + return 0; 149 + } 150 + 151 + static void __exit alsa_card_adlib_exit(void) 152 + { 153 + int i; 154 + 155 + for (i = 0; i < SNDRV_CARDS; i++) 156 + platform_device_unregister(devices[i]); 157 + platform_driver_unregister(&snd_adlib_driver); 158 + } 159 + 160 + module_init(alsa_card_adlib_init); 161 + module_exit(alsa_card_adlib_exit);
+2 -2
sound/isa/cmi8330.c
··· 693 if ((err = platform_driver_register(&snd_cmi8330_driver)) < 0) 694 return err; 695 696 - for (i = 0; i < SNDRV_CARDS && enable[i]; i++) { 697 struct platform_device *device; 698 - if (is_isapnp_selected(i)) 699 continue; 700 device = platform_device_register_simple(CMI8330_DRIVER, 701 i, NULL, 0);
··· 693 if ((err = platform_driver_register(&snd_cmi8330_driver)) < 0) 694 return err; 695 696 + for (i = 0; i < SNDRV_CARDS; i++) { 697 struct platform_device *device; 698 + if (! enable[i] || is_isapnp_selected(i)) 699 continue; 700 device = platform_device_register_simple(CMI8330_DRIVER, 701 i, NULL, 0);
+2
sound/isa/opti9xx/Makefile
··· 6 snd-opti92x-ad1848-objs := opti92x-ad1848.o 7 snd-opti92x-cs4231-objs := opti92x-cs4231.o 8 snd-opti93x-objs := opti93x.o 9 10 # Toplevel Module Dependency 11 obj-$(CONFIG_SND_OPTI92X_AD1848) += snd-opti92x-ad1848.o 12 obj-$(CONFIG_SND_OPTI92X_CS4231) += snd-opti92x-cs4231.o 13 obj-$(CONFIG_SND_OPTI93X) += snd-opti93x.o
··· 6 snd-opti92x-ad1848-objs := opti92x-ad1848.o 7 snd-opti92x-cs4231-objs := opti92x-cs4231.o 8 snd-opti93x-objs := opti93x.o 9 + snd-miro-objs := miro.o 10 11 # Toplevel Module Dependency 12 obj-$(CONFIG_SND_OPTI92X_AD1848) += snd-opti92x-ad1848.o 13 obj-$(CONFIG_SND_OPTI92X_CS4231) += snd-opti92x-cs4231.o 14 obj-$(CONFIG_SND_OPTI93X) += snd-opti93x.o 15 + obj-$(CONFIG_SND_MIRO) += snd-miro.o
+1455
sound/isa/opti9xx/miro.c
···
··· 1 + /* 2 + * ALSA soundcard driver for Miro miroSOUND PCM1 pro 3 + * miroSOUND PCM12 4 + * miroSOUND PCM20 Radio 5 + * 6 + * Copyright (C) 2004-2005 Martin Langer <martin-langer@gmx.de> 7 + * 8 + * Based on OSS ACI and ALSA OPTi9xx drivers 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + * 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + * 20 + * You should have received a copy of the GNU General Public License 21 + * along with this program; if not, write to the Free Software 22 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 + */ 24 + 25 + #include <sound/driver.h> 26 + #include <linux/init.h> 27 + #include <linux/err.h> 28 + #include <linux/platform_device.h> 29 + #include <linux/delay.h> 30 + #include <linux/slab.h> 31 + #include <linux/ioport.h> 32 + #include <linux/moduleparam.h> 33 + #include <asm/io.h> 34 + #include <asm/dma.h> 35 + #include <sound/core.h> 36 + #include <sound/cs4231.h> 37 + #include <sound/mpu401.h> 38 + #include <sound/opl4.h> 39 + #include <sound/control.h> 40 + #include <sound/info.h> 41 + #define SNDRV_LEGACY_FIND_FREE_IRQ 42 + #define SNDRV_LEGACY_FIND_FREE_DMA 43 + #include <sound/initval.h> 44 + #include "miro.h" 45 + 46 + MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>"); 47 + MODULE_LICENSE("GPL"); 48 + MODULE_DESCRIPTION("Miro miroSOUND PCM1 pro, PCM12, PCM20 Radio"); 49 + MODULE_SUPPORTED_DEVICE("{{Miro,miroSOUND PCM1 pro}, " 50 + "{Miro,miroSOUND PCM12}, " 51 + "{Miro,miroSOUND PCM20 Radio}}"); 52 + 53 + static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ 54 + static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ 55 + static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */ 56 + static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */ 57 + static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */ 58 + static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */ 59 + static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */ 60 + static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ 61 + static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ 62 + static int wss; 63 + static int ide; 64 + 65 + module_param(index, int, 0444); 66 + MODULE_PARM_DESC(index, "Index value for miro soundcard."); 67 + module_param(id, charp, 0444); 68 + MODULE_PARM_DESC(id, "ID string for miro soundcard."); 69 + module_param(port, long, 0444); 70 + MODULE_PARM_DESC(port, "WSS port # for miro driver."); 71 + module_param(mpu_port, long, 0444); 72 + MODULE_PARM_DESC(mpu_port, "MPU-401 port # for miro driver."); 73 + module_param(fm_port, long, 0444); 74 + MODULE_PARM_DESC(fm_port, "FM Port # for miro driver."); 75 + module_param(irq, int, 0444); 76 + MODULE_PARM_DESC(irq, "WSS irq # for miro driver."); 77 + module_param(mpu_irq, int, 0444); 78 + MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for miro driver."); 79 + module_param(dma1, int, 0444); 80 + MODULE_PARM_DESC(dma1, "1st dma # for miro driver."); 81 + module_param(dma2, int, 0444); 82 + MODULE_PARM_DESC(dma2, "2nd dma # for miro driver."); 83 + module_param(wss, int, 0444); 84 + MODULE_PARM_DESC(wss, "wss mode"); 85 + module_param(ide, int, 0444); 86 + MODULE_PARM_DESC(ide, "enable ide port"); 87 + 88 + #define OPTi9XX_HW_DETECT 0 89 + #define OPTi9XX_HW_82C928 1 90 + #define OPTi9XX_HW_82C929 2 91 + #define OPTi9XX_HW_82C924 3 92 + #define OPTi9XX_HW_82C925 4 93 + #define OPTi9XX_HW_82C930 5 94 + #define OPTi9XX_HW_82C931 6 95 + #define OPTi9XX_HW_82C933 7 96 + #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933 97 + 98 + #define OPTi9XX_MC_REG(n) n 99 + 100 + 101 + struct snd_miro { 102 + unsigned short hardware; 103 + unsigned char password; 104 + char name[7]; 105 + 106 + struct resource *res_mc_base; 107 + struct resource *res_aci_port; 108 + 109 + unsigned long mc_base; 110 + unsigned long mc_base_size; 111 + unsigned long pwd_reg; 112 + 113 + spinlock_t lock; 114 + struct snd_card *card; 115 + struct snd_pcm *pcm; 116 + 117 + long wss_base; 118 + int irq; 119 + int dma1; 120 + int dma2; 121 + 122 + long fm_port; 123 + 124 + long mpu_port; 125 + int mpu_irq; 126 + 127 + unsigned long aci_port; 128 + int aci_vendor; 129 + int aci_product; 130 + int aci_version; 131 + int aci_amp; 132 + int aci_preamp; 133 + int aci_solomode; 134 + 135 + struct mutex aci_mutex; 136 + }; 137 + 138 + static void snd_miro_proc_init(struct snd_miro * miro); 139 + 140 + #define DRIVER_NAME "snd-miro" 141 + 142 + static struct platform_device *device; 143 + 144 + static char * snd_opti9xx_names[] = { 145 + "unkown", 146 + "82C928", "82C929", 147 + "82C924", "82C925", 148 + "82C930", "82C931", "82C933" 149 + }; 150 + 151 + /* 152 + * ACI control 153 + */ 154 + 155 + static int aci_busy_wait(struct snd_miro * miro) 156 + { 157 + long timeout; 158 + unsigned char byte; 159 + 160 + for (timeout = 1; timeout <= ACI_MINTIME+30; timeout++) { 161 + if (((byte=inb(miro->aci_port + ACI_REG_BUSY)) & 1) == 0) { 162 + if (timeout >= ACI_MINTIME) 163 + snd_printd("aci ready in round %ld.\n", 164 + timeout-ACI_MINTIME); 165 + return byte; 166 + } 167 + if (timeout >= ACI_MINTIME) { 168 + long out=10*HZ; 169 + switch (timeout-ACI_MINTIME) { 170 + case 0 ... 9: 171 + out /= 10; 172 + case 10 ... 19: 173 + out /= 10; 174 + case 20 ... 30: 175 + out /= 10; 176 + default: 177 + set_current_state(TASK_UNINTERRUPTIBLE); 178 + schedule_timeout(out); 179 + break; 180 + } 181 + } 182 + } 183 + snd_printk(KERN_ERR "aci_busy_wait() time out\n"); 184 + return -EBUSY; 185 + } 186 + 187 + static inline int aci_write(struct snd_miro * miro, unsigned char byte) 188 + { 189 + if (aci_busy_wait(miro) >= 0) { 190 + outb(byte, miro->aci_port + ACI_REG_COMMAND); 191 + return 0; 192 + } else { 193 + snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte); 194 + return -EBUSY; 195 + } 196 + } 197 + 198 + static inline int aci_read(struct snd_miro * miro) 199 + { 200 + unsigned char byte; 201 + 202 + if (aci_busy_wait(miro) >= 0) { 203 + byte=inb(miro->aci_port + ACI_REG_STATUS); 204 + return byte; 205 + } else { 206 + snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n"); 207 + return -EBUSY; 208 + } 209 + } 210 + 211 + static int aci_cmd(struct snd_miro * miro, int write1, int write2, int write3) 212 + { 213 + int write[] = {write1, write2, write3}; 214 + int value, i; 215 + 216 + if (mutex_lock_interruptible(&miro->aci_mutex)) 217 + return -EINTR; 218 + 219 + for (i=0; i<3; i++) { 220 + if (write[i]< 0 || write[i] > 255) 221 + break; 222 + else { 223 + value = aci_write(miro, write[i]); 224 + if (value < 0) 225 + goto out; 226 + } 227 + } 228 + 229 + value = aci_read(miro); 230 + 231 + out: mutex_unlock(&miro->aci_mutex); 232 + return value; 233 + } 234 + 235 + static int aci_getvalue(struct snd_miro * miro, unsigned char index) 236 + { 237 + return aci_cmd(miro, ACI_STATUS, index, -1); 238 + } 239 + 240 + static int aci_setvalue(struct snd_miro * miro, unsigned char index, int value) 241 + { 242 + return aci_cmd(miro, index, value, -1); 243 + } 244 + 245 + /* 246 + * MIXER part 247 + */ 248 + 249 + static int snd_miro_info_capture(struct snd_kcontrol *kcontrol, 250 + struct snd_ctl_elem_info *uinfo) 251 + { 252 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 253 + uinfo->count = 1; 254 + 255 + return 0; 256 + } 257 + 258 + static int snd_miro_get_capture(struct snd_kcontrol *kcontrol, 259 + struct snd_ctl_elem_value *ucontrol) 260 + { 261 + struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 262 + int value; 263 + 264 + if ((value = aci_getvalue(miro, ACI_S_GENERAL)) < 0) { 265 + snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n", value); 266 + return value; 267 + } 268 + 269 + ucontrol->value.integer.value[0] = value & 0x20; 270 + 271 + return 0; 272 + } 273 + 274 + static int snd_miro_put_capture(struct snd_kcontrol *kcontrol, 275 + struct snd_ctl_elem_value *ucontrol) 276 + { 277 + struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 278 + int change, value, error; 279 + 280 + value = !(ucontrol->value.integer.value[0]); 281 + 282 + if ((error = aci_setvalue(miro, ACI_SET_SOLOMODE, value)) < 0) { 283 + snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n", error); 284 + return error; 285 + } 286 + 287 + change = (value != miro->aci_solomode); 288 + miro->aci_solomode = value; 289 + 290 + return change; 291 + } 292 + 293 + static int snd_miro_info_preamp(struct snd_kcontrol *kcontrol, 294 + struct snd_ctl_elem_info *uinfo) 295 + { 296 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 297 + uinfo->count = 1; 298 + uinfo->value.integer.min = 0; 299 + uinfo->value.integer.max = 3; 300 + 301 + return 0; 302 + } 303 + 304 + static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol, 305 + struct snd_ctl_elem_value *ucontrol) 306 + { 307 + struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 308 + int value; 309 + 310 + if (miro->aci_version <= 176) { 311 + 312 + /* 313 + OSS says it's not readable with versions < 176. 314 + But it doesn't work on my card, 315 + which is a PCM12 with aci_version = 176. 316 + */ 317 + 318 + ucontrol->value.integer.value[0] = miro->aci_preamp; 319 + return 0; 320 + } 321 + 322 + if ((value = aci_getvalue(miro, ACI_GET_PREAMP)) < 0) { 323 + snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n", value); 324 + return value; 325 + } 326 + 327 + ucontrol->value.integer.value[0] = value; 328 + 329 + return 0; 330 + } 331 + 332 + static int snd_miro_put_preamp(struct snd_kcontrol *kcontrol, 333 + struct snd_ctl_elem_value *ucontrol) 334 + { 335 + struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 336 + int error, value, change; 337 + 338 + value = ucontrol->value.integer.value[0]; 339 + 340 + if ((error = aci_setvalue(miro, ACI_SET_PREAMP, value)) < 0) { 341 + snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n", error); 342 + return error; 343 + } 344 + 345 + change = (value != miro->aci_preamp); 346 + miro->aci_preamp = value; 347 + 348 + return change; 349 + } 350 + 351 + static int snd_miro_info_amp(struct snd_kcontrol *kcontrol, 352 + struct snd_ctl_elem_info *uinfo) 353 + { 354 + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 355 + uinfo->count = 1; 356 + 357 + return 0; 358 + } 359 + 360 + static int snd_miro_get_amp(struct snd_kcontrol *kcontrol, 361 + struct snd_ctl_elem_value *ucontrol) 362 + { 363 + struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 364 + ucontrol->value.integer.value[0] = miro->aci_amp; 365 + 366 + return 0; 367 + } 368 + 369 + static int snd_miro_put_amp(struct snd_kcontrol *kcontrol, 370 + struct snd_ctl_elem_value *ucontrol) 371 + { 372 + struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 373 + int error, value, change; 374 + 375 + value = ucontrol->value.integer.value[0]; 376 + 377 + if ((error = aci_setvalue(miro, ACI_SET_POWERAMP, value)) < 0) { 378 + snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error); 379 + return error; 380 + } 381 + 382 + change = (value != miro->aci_amp); 383 + miro->aci_amp = value; 384 + 385 + return change; 386 + } 387 + 388 + #define MIRO_DOUBLE(ctl_name, ctl_index, get_right_reg, set_right_reg) \ 389 + { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 390 + .name = ctl_name, \ 391 + .index = ctl_index, \ 392 + .info = snd_miro_info_double, \ 393 + .get = snd_miro_get_double, \ 394 + .put = snd_miro_put_double, \ 395 + .private_value = get_right_reg | (set_right_reg << 8) \ 396 + } 397 + 398 + static int snd_miro_info_double(struct snd_kcontrol *kcontrol, 399 + struct snd_ctl_elem_info *uinfo) 400 + { 401 + int reg = kcontrol->private_value & 0xff; 402 + 403 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 404 + uinfo->count = 2; 405 + 406 + if ((reg >= ACI_GET_EQ1) && (reg <= ACI_GET_EQ7)) { 407 + 408 + /* equalizer elements */ 409 + 410 + uinfo->value.integer.min = - 0x7f; 411 + uinfo->value.integer.max = 0x7f; 412 + } else { 413 + 414 + /* non-equalizer elements */ 415 + 416 + uinfo->value.integer.min = 0; 417 + uinfo->value.integer.max = 0x20; 418 + } 419 + 420 + return 0; 421 + } 422 + 423 + static int snd_miro_get_double(struct snd_kcontrol *kcontrol, 424 + struct snd_ctl_elem_value *uinfo) 425 + { 426 + struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 427 + int left_val, right_val; 428 + 429 + int right_reg = kcontrol->private_value & 0xff; 430 + int left_reg = right_reg + 1; 431 + 432 + if ((right_val = aci_getvalue(miro, right_reg)) < 0) { 433 + snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val); 434 + return right_val; 435 + } 436 + 437 + if ((left_val = aci_getvalue(miro, left_reg)) < 0) { 438 + snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val); 439 + return left_val; 440 + } 441 + 442 + if ((right_reg >= ACI_GET_EQ1) && (right_reg <= ACI_GET_EQ7)) { 443 + 444 + /* equalizer elements */ 445 + 446 + if (left_val < 0x80) { 447 + uinfo->value.integer.value[0] = left_val; 448 + } else { 449 + uinfo->value.integer.value[0] = 0x80 - left_val; 450 + } 451 + 452 + if (right_val < 0x80) { 453 + uinfo->value.integer.value[1] = right_val; 454 + } else { 455 + uinfo->value.integer.value[1] = 0x80 - right_val; 456 + } 457 + 458 + } else { 459 + 460 + /* non-equalizer elements */ 461 + 462 + uinfo->value.integer.value[0] = 0x20 - left_val; 463 + uinfo->value.integer.value[1] = 0x20 - right_val; 464 + } 465 + 466 + return 0; 467 + } 468 + 469 + static int snd_miro_put_double(struct snd_kcontrol *kcontrol, 470 + struct snd_ctl_elem_value *ucontrol) 471 + { 472 + struct snd_miro *miro = snd_kcontrol_chip(kcontrol); 473 + int left, right, left_old, right_old; 474 + int setreg_left, setreg_right, getreg_left, getreg_right; 475 + int change, error; 476 + 477 + left = ucontrol->value.integer.value[0]; 478 + right = ucontrol->value.integer.value[1]; 479 + 480 + setreg_right = (kcontrol->private_value >> 8) & 0xff; 481 + if (setreg_right == ACI_SET_MASTER) { 482 + setreg_left = setreg_right + 1; 483 + } else { 484 + setreg_left = setreg_right + 8; 485 + } 486 + 487 + getreg_right = kcontrol->private_value & 0xff; 488 + getreg_left = getreg_right + 1; 489 + 490 + if ((left_old = aci_getvalue(miro, getreg_left)) < 0) { 491 + snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old); 492 + return left_old; 493 + } 494 + 495 + if ((right_old = aci_getvalue(miro, getreg_right)) < 0) { 496 + snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old); 497 + return right_old; 498 + } 499 + 500 + if ((getreg_right >= ACI_GET_EQ1) && (getreg_right <= ACI_GET_EQ7)) { 501 + 502 + /* equalizer elements */ 503 + 504 + if (left_old > 0x80) 505 + left_old = 0x80 - left_old; 506 + if (right_old > 0x80) 507 + right_old = 0x80 - right_old; 508 + 509 + if (left >= 0) { 510 + if ((error = aci_setvalue(miro, setreg_left, left)) < 0) { 511 + snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 512 + left, error); 513 + return error; 514 + } 515 + } else { 516 + if ((error = aci_setvalue(miro, setreg_left, 0x80 - left)) < 0) { 517 + snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 518 + 0x80 - left, error); 519 + return error; 520 + } 521 + } 522 + 523 + if (right >= 0) { 524 + if ((error = aci_setvalue(miro, setreg_right, right)) < 0) { 525 + snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 526 + right, error); 527 + return error; 528 + } 529 + } else { 530 + if ((error = aci_setvalue(miro, setreg_right, 0x80 - right)) < 0) { 531 + snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 532 + 0x80 - right, error); 533 + return error; 534 + } 535 + } 536 + 537 + } else { 538 + 539 + /* non-equalizer elements */ 540 + 541 + left_old = 0x20 - left_old; 542 + right_old = 0x20 - right_old; 543 + 544 + if ((error = aci_setvalue(miro, setreg_left, 0x20 - left)) < 0) { 545 + snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 546 + 0x20 - left, error); 547 + return error; 548 + } 549 + if ((error = aci_setvalue(miro, setreg_right, 0x20 - right)) < 0) { 550 + snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 551 + 0x20 - right, error); 552 + return error; 553 + } 554 + } 555 + 556 + change = (left != left_old) || (right != right_old); 557 + 558 + return change; 559 + } 560 + 561 + static struct snd_kcontrol_new snd_miro_controls[] = { 562 + MIRO_DOUBLE("Master Playback Volume", 0, ACI_GET_MASTER, ACI_SET_MASTER), 563 + MIRO_DOUBLE("Mic Playback Volume", 1, ACI_GET_MIC, ACI_SET_MIC), 564 + MIRO_DOUBLE("Line Playback Volume", 1, ACI_GET_LINE, ACI_SET_LINE), 565 + MIRO_DOUBLE("CD Playback Volume", 0, ACI_GET_CD, ACI_SET_CD), 566 + MIRO_DOUBLE("Synth Playback Volume", 0, ACI_GET_SYNTH, ACI_SET_SYNTH), 567 + MIRO_DOUBLE("PCM Playback Volume", 1, ACI_GET_PCM, ACI_SET_PCM), 568 + MIRO_DOUBLE("Aux Playback Volume", 2, ACI_GET_LINE2, ACI_SET_LINE2), 569 + }; 570 + 571 + /* Equalizer with seven bands (only PCM20) 572 + from -12dB up to +12dB on each band */ 573 + static struct snd_kcontrol_new snd_miro_eq_controls[] = { 574 + MIRO_DOUBLE("Tone Control - 28 Hz", 0, ACI_GET_EQ1, ACI_SET_EQ1), 575 + MIRO_DOUBLE("Tone Control - 160 Hz", 0, ACI_GET_EQ2, ACI_SET_EQ2), 576 + MIRO_DOUBLE("Tone Control - 400 Hz", 0, ACI_GET_EQ3, ACI_SET_EQ3), 577 + MIRO_DOUBLE("Tone Control - 1 kHz", 0, ACI_GET_EQ4, ACI_SET_EQ4), 578 + MIRO_DOUBLE("Tone Control - 2.5 kHz", 0, ACI_GET_EQ5, ACI_SET_EQ5), 579 + MIRO_DOUBLE("Tone Control - 6.3 kHz", 0, ACI_GET_EQ6, ACI_SET_EQ6), 580 + MIRO_DOUBLE("Tone Control - 16 kHz", 0, ACI_GET_EQ7, ACI_SET_EQ7), 581 + }; 582 + 583 + static struct snd_kcontrol_new snd_miro_radio_control[] = { 584 + MIRO_DOUBLE("Radio Playback Volume", 0, ACI_GET_LINE1, ACI_SET_LINE1), 585 + }; 586 + 587 + static struct snd_kcontrol_new snd_miro_line_control[] = { 588 + MIRO_DOUBLE("Line Playback Volume", 2, ACI_GET_LINE1, ACI_SET_LINE1), 589 + }; 590 + 591 + static struct snd_kcontrol_new snd_miro_preamp_control[] = { 592 + { 593 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 594 + .name = "Mic Boost", 595 + .index = 1, 596 + .info = snd_miro_info_preamp, 597 + .get = snd_miro_get_preamp, 598 + .put = snd_miro_put_preamp, 599 + }}; 600 + 601 + static struct snd_kcontrol_new snd_miro_amp_control[] = { 602 + { 603 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 604 + .name = "Line Boost", 605 + .index = 0, 606 + .info = snd_miro_info_amp, 607 + .get = snd_miro_get_amp, 608 + .put = snd_miro_put_amp, 609 + }}; 610 + 611 + static struct snd_kcontrol_new snd_miro_capture_control[] = { 612 + { 613 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 614 + .name = "PCM Capture Switch", 615 + .index = 0, 616 + .info = snd_miro_info_capture, 617 + .get = snd_miro_get_capture, 618 + .put = snd_miro_put_capture, 619 + }}; 620 + 621 + static unsigned char aci_init_values[][2] __initdata = { 622 + { ACI_SET_MUTE, 0x00 }, 623 + { ACI_SET_POWERAMP, 0x00 }, 624 + { ACI_SET_PREAMP, 0x00 }, 625 + { ACI_SET_SOLOMODE, 0x00 }, 626 + { ACI_SET_MIC + 0, 0x20 }, 627 + { ACI_SET_MIC + 8, 0x20 }, 628 + { ACI_SET_LINE + 0, 0x20 }, 629 + { ACI_SET_LINE + 8, 0x20 }, 630 + { ACI_SET_CD + 0, 0x20 }, 631 + { ACI_SET_CD + 8, 0x20 }, 632 + { ACI_SET_PCM + 0, 0x20 }, 633 + { ACI_SET_PCM + 8, 0x20 }, 634 + { ACI_SET_LINE1 + 0, 0x20 }, 635 + { ACI_SET_LINE1 + 8, 0x20 }, 636 + { ACI_SET_LINE2 + 0, 0x20 }, 637 + { ACI_SET_LINE2 + 8, 0x20 }, 638 + { ACI_SET_SYNTH + 0, 0x20 }, 639 + { ACI_SET_SYNTH + 8, 0x20 }, 640 + { ACI_SET_MASTER + 0, 0x20 }, 641 + { ACI_SET_MASTER + 1, 0x20 }, 642 + }; 643 + 644 + static int __init snd_set_aci_init_values(struct snd_miro *miro) 645 + { 646 + int idx, error; 647 + 648 + /* enable WSS on PCM1 */ 649 + 650 + if ((miro->aci_product == 'A') && wss) { 651 + if ((error = aci_setvalue(miro, ACI_SET_WSS, wss)) < 0) { 652 + snd_printk(KERN_ERR "enabling WSS mode failed\n"); 653 + return error; 654 + } 655 + } 656 + 657 + /* enable IDE port */ 658 + 659 + if (ide) { 660 + if ((error = aci_setvalue(miro, ACI_SET_IDE, ide)) < 0) { 661 + snd_printk(KERN_ERR "enabling IDE port failed\n"); 662 + return error; 663 + } 664 + } 665 + 666 + /* set common aci values */ 667 + 668 + for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++) 669 + if ((error = aci_setvalue(miro, aci_init_values[idx][0], 670 + aci_init_values[idx][1])) < 0) { 671 + snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", 672 + aci_init_values[idx][0], error); 673 + return error; 674 + } 675 + 676 + miro->aci_amp = 0; 677 + miro->aci_preamp = 0; 678 + miro->aci_solomode = 1; 679 + 680 + return 0; 681 + } 682 + 683 + static int snd_miro_mixer(struct snd_miro *miro) 684 + { 685 + struct snd_card *card; 686 + unsigned int idx; 687 + int err; 688 + 689 + snd_assert(miro != NULL && miro->card != NULL, return -EINVAL); 690 + 691 + card = miro->card; 692 + 693 + switch (miro->hardware) { 694 + case OPTi9XX_HW_82C924: 695 + strcpy(card->mixername, "ACI & OPTi924"); 696 + break; 697 + case OPTi9XX_HW_82C929: 698 + strcpy(card->mixername, "ACI & OPTi929"); 699 + break; 700 + default: 701 + snd_BUG(); 702 + break; 703 + } 704 + 705 + for (idx = 0; idx < ARRAY_SIZE(snd_miro_controls); idx++) { 706 + if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_controls[idx], miro))) < 0) 707 + return err; 708 + } 709 + 710 + if ((miro->aci_product == 'A') || (miro->aci_product == 'B')) { 711 + /* PCM1/PCM12 with power-amp and Line 2 */ 712 + if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_line_control[0], miro))) < 0) 713 + return err; 714 + if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_amp_control[0], miro))) < 0) 715 + return err; 716 + } 717 + 718 + if ((miro->aci_product == 'B') || (miro->aci_product == 'C')) { 719 + /* PCM12/PCM20 with mic-preamp */ 720 + if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_preamp_control[0], miro))) < 0) 721 + return err; 722 + if (miro->aci_version >= 176) 723 + if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_capture_control[0], miro))) < 0) 724 + return err; 725 + } 726 + 727 + if (miro->aci_product == 'C') { 728 + /* PCM20 with radio and 7 band equalizer */ 729 + if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_radio_control[0], miro))) < 0) 730 + return err; 731 + for (idx = 0; idx < ARRAY_SIZE(snd_miro_eq_controls); idx++) { 732 + if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_eq_controls[idx], miro))) < 0) 733 + return err; 734 + } 735 + } 736 + 737 + return 0; 738 + } 739 + 740 + static long snd_legacy_find_free_ioport(long *port_table, long size) 741 + { 742 + while (*port_table != -1) { 743 + struct resource *res; 744 + if ((res = request_region(*port_table, size, 745 + "ALSA test")) != NULL) { 746 + release_and_free_resource(res); 747 + return *port_table; 748 + } 749 + port_table++; 750 + } 751 + return -1; 752 + } 753 + 754 + static int __init snd_miro_init(struct snd_miro *chip, unsigned short hardware) 755 + { 756 + static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2}; 757 + 758 + chip->hardware = hardware; 759 + strcpy(chip->name, snd_opti9xx_names[hardware]); 760 + 761 + chip->mc_base_size = opti9xx_mc_size[hardware]; 762 + 763 + spin_lock_init(&chip->lock); 764 + 765 + chip->wss_base = -1; 766 + chip->irq = -1; 767 + chip->dma1 = -1; 768 + chip->dma2 = -1; 769 + chip->fm_port = -1; 770 + chip->mpu_port = -1; 771 + chip->mpu_irq = -1; 772 + 773 + switch (hardware) { 774 + case OPTi9XX_HW_82C929: 775 + chip->mc_base = 0xf8c; 776 + chip->password = 0xe3; 777 + chip->pwd_reg = 3; 778 + break; 779 + 780 + case OPTi9XX_HW_82C924: 781 + chip->mc_base = 0xf8c; 782 + chip->password = 0xe5; 783 + chip->pwd_reg = 3; 784 + break; 785 + 786 + default: 787 + snd_printk(KERN_ERR "sorry, no support for %d\n", hardware); 788 + return -ENODEV; 789 + } 790 + 791 + return 0; 792 + } 793 + 794 + static unsigned char snd_miro_read(struct snd_miro *chip, 795 + unsigned char reg) 796 + { 797 + unsigned long flags; 798 + unsigned char retval = 0xff; 799 + 800 + spin_lock_irqsave(&chip->lock, flags); 801 + outb(chip->password, chip->mc_base + chip->pwd_reg); 802 + 803 + switch (chip->hardware) { 804 + case OPTi9XX_HW_82C924: 805 + if (reg > 7) { 806 + outb(reg, chip->mc_base + 8); 807 + outb(chip->password, chip->mc_base + chip->pwd_reg); 808 + retval = inb(chip->mc_base + 9); 809 + break; 810 + } 811 + 812 + case OPTi9XX_HW_82C929: 813 + retval = inb(chip->mc_base + reg); 814 + break; 815 + 816 + default: 817 + snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware); 818 + } 819 + 820 + spin_unlock_irqrestore(&chip->lock, flags); 821 + return retval; 822 + } 823 + 824 + static void snd_miro_write(struct snd_miro *chip, unsigned char reg, 825 + unsigned char value) 826 + { 827 + unsigned long flags; 828 + 829 + spin_lock_irqsave(&chip->lock, flags); 830 + outb(chip->password, chip->mc_base + chip->pwd_reg); 831 + 832 + switch (chip->hardware) { 833 + case OPTi9XX_HW_82C924: 834 + if (reg > 7) { 835 + outb(reg, chip->mc_base + 8); 836 + outb(chip->password, chip->mc_base + chip->pwd_reg); 837 + outb(value, chip->mc_base + 9); 838 + break; 839 + } 840 + 841 + case OPTi9XX_HW_82C929: 842 + outb(value, chip->mc_base + reg); 843 + break; 844 + 845 + default: 846 + snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware); 847 + } 848 + 849 + spin_unlock_irqrestore(&chip->lock, flags); 850 + } 851 + 852 + 853 + #define snd_miro_write_mask(chip, reg, value, mask) \ 854 + snd_miro_write(chip, reg, \ 855 + (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask))) 856 + 857 + /* 858 + * Proc Interface 859 + */ 860 + 861 + static void snd_miro_proc_read(struct snd_info_entry * entry, 862 + struct snd_info_buffer *buffer) 863 + { 864 + struct snd_miro *miro = (struct snd_miro *) entry->private_data; 865 + char* model = "unknown"; 866 + 867 + /* miroSOUND PCM1 pro, early PCM12 */ 868 + 869 + if ((miro->hardware == OPTi9XX_HW_82C929) && 870 + (miro->aci_vendor == 'm') && 871 + (miro->aci_product == 'A')) { 872 + switch(miro->aci_version) { 873 + case 3: 874 + model = "miroSOUND PCM1 pro"; 875 + break; 876 + default: 877 + model = "miroSOUND PCM1 pro / (early) PCM12"; 878 + break; 879 + } 880 + } 881 + 882 + /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */ 883 + 884 + if ((miro->hardware == OPTi9XX_HW_82C924) && 885 + (miro->aci_vendor == 'm') && 886 + (miro->aci_product == 'B')) { 887 + switch(miro->aci_version) { 888 + case 4: 889 + model = "miroSOUND PCM12"; 890 + break; 891 + case 176: 892 + model = "miroSOUND PCM12 (Rev. E)"; 893 + break; 894 + default: 895 + model = "miroSOUND PCM12 / PCM12 pnp"; 896 + break; 897 + } 898 + } 899 + 900 + /* miroSOUND PCM20 radio */ 901 + 902 + if ((miro->hardware == OPTi9XX_HW_82C924) && 903 + (miro->aci_vendor == 'm') && 904 + (miro->aci_product == 'C')) { 905 + switch(miro->aci_version) { 906 + case 7: 907 + model = "miroSOUND PCM20 radio (Rev. E)"; 908 + break; 909 + default: 910 + model = "miroSOUND PCM20 radio"; 911 + break; 912 + } 913 + } 914 + 915 + snd_iprintf(buffer, "\nGeneral information:\n"); 916 + snd_iprintf(buffer, " model : %s\n", model); 917 + snd_iprintf(buffer, " opti : %s\n", miro->name); 918 + snd_iprintf(buffer, " codec : %s\n", miro->pcm->name); 919 + snd_iprintf(buffer, " port : 0x%lx\n", miro->wss_base); 920 + snd_iprintf(buffer, " irq : %d\n", miro->irq); 921 + snd_iprintf(buffer, " dma : %d,%d\n\n", miro->dma1, miro->dma2); 922 + 923 + snd_iprintf(buffer, "MPU-401:\n"); 924 + snd_iprintf(buffer, " port : 0x%lx\n", miro->mpu_port); 925 + snd_iprintf(buffer, " irq : %d\n\n", miro->mpu_irq); 926 + 927 + snd_iprintf(buffer, "ACI information:\n"); 928 + snd_iprintf(buffer, " vendor : "); 929 + switch(miro->aci_vendor) { 930 + case 'm': 931 + snd_iprintf(buffer, "Miro\n"); 932 + break; 933 + default: 934 + snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_vendor); 935 + break; 936 + } 937 + 938 + snd_iprintf(buffer, " product : "); 939 + switch(miro->aci_product) { 940 + case 'A': 941 + snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n"); 942 + break; 943 + case 'B': 944 + snd_iprintf(buffer, "miroSOUND PCM12\n"); 945 + break; 946 + case 'C': 947 + snd_iprintf(buffer, "miroSOUND PCM20 radio\n"); 948 + break; 949 + default: 950 + snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_product); 951 + break; 952 + } 953 + 954 + snd_iprintf(buffer, " firmware: %d (0x%x)\n", 955 + miro->aci_version, miro->aci_version); 956 + snd_iprintf(buffer, " port : 0x%lx-0x%lx\n", 957 + miro->aci_port, miro->aci_port+2); 958 + snd_iprintf(buffer, " wss : 0x%x\n", wss); 959 + snd_iprintf(buffer, " ide : 0x%x\n", ide); 960 + snd_iprintf(buffer, " solomode: 0x%x\n", miro->aci_solomode); 961 + snd_iprintf(buffer, " amp : 0x%x\n", miro->aci_amp); 962 + snd_iprintf(buffer, " preamp : 0x%x\n", miro->aci_preamp); 963 + } 964 + 965 + static void __init snd_miro_proc_init(struct snd_miro * miro) 966 + { 967 + struct snd_info_entry *entry; 968 + 969 + if (! snd_card_proc_new(miro->card, "miro", &entry)) 970 + snd_info_set_text_ops(entry, miro, 1024, snd_miro_proc_read); 971 + } 972 + 973 + /* 974 + * Init 975 + */ 976 + 977 + static int __init snd_miro_configure(struct snd_miro *chip) 978 + { 979 + unsigned char wss_base_bits; 980 + unsigned char irq_bits; 981 + unsigned char dma_bits; 982 + unsigned char mpu_port_bits = 0; 983 + unsigned char mpu_irq_bits; 984 + unsigned long flags; 985 + 986 + switch (chip->hardware) { 987 + case OPTi9XX_HW_82C924: 988 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02); 989 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); 990 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */ 991 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff); 992 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); 993 + break; 994 + case OPTi9XX_HW_82C929: 995 + /* untested init commands for OPTi929 */ 996 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); 997 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */ 998 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c); 999 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); 1000 + break; 1001 + default: 1002 + snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware); 1003 + return -EINVAL; 1004 + } 1005 + 1006 + switch (chip->wss_base) { 1007 + case 0x530: 1008 + wss_base_bits = 0x00; 1009 + break; 1010 + case 0x604: 1011 + wss_base_bits = 0x03; 1012 + break; 1013 + case 0xe80: 1014 + wss_base_bits = 0x01; 1015 + break; 1016 + case 0xf40: 1017 + wss_base_bits = 0x02; 1018 + break; 1019 + default: 1020 + snd_printk(KERN_ERR "WSS port 0x%lx not valid\n", chip->wss_base); 1021 + goto __skip_base; 1022 + } 1023 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30); 1024 + 1025 + __skip_base: 1026 + switch (chip->irq) { 1027 + case 5: 1028 + irq_bits = 0x05; 1029 + break; 1030 + case 7: 1031 + irq_bits = 0x01; 1032 + break; 1033 + case 9: 1034 + irq_bits = 0x02; 1035 + break; 1036 + case 10: 1037 + irq_bits = 0x03; 1038 + break; 1039 + case 11: 1040 + irq_bits = 0x04; 1041 + break; 1042 + default: 1043 + snd_printk(KERN_ERR "WSS irq # %d not valid\n", chip->irq); 1044 + goto __skip_resources; 1045 + } 1046 + 1047 + switch (chip->dma1) { 1048 + case 0: 1049 + dma_bits = 0x01; 1050 + break; 1051 + case 1: 1052 + dma_bits = 0x02; 1053 + break; 1054 + case 3: 1055 + dma_bits = 0x03; 1056 + break; 1057 + default: 1058 + snd_printk(KERN_ERR "WSS dma1 # %d not valid\n", chip->dma1); 1059 + goto __skip_resources; 1060 + } 1061 + 1062 + if (chip->dma1 == chip->dma2) { 1063 + snd_printk(KERN_ERR "don't want to share dmas\n"); 1064 + return -EBUSY; 1065 + } 1066 + 1067 + switch (chip->dma2) { 1068 + case 0: 1069 + case 1: 1070 + break; 1071 + default: 1072 + snd_printk(KERN_ERR "WSS dma2 # %d not valid\n", chip->dma2); 1073 + goto __skip_resources; 1074 + } 1075 + dma_bits |= 0x04; 1076 + 1077 + spin_lock_irqsave(&chip->lock, flags); 1078 + outb(irq_bits << 3 | dma_bits, chip->wss_base); 1079 + spin_unlock_irqrestore(&chip->lock, flags); 1080 + 1081 + __skip_resources: 1082 + if (chip->hardware > OPTi9XX_HW_82C928) { 1083 + switch (chip->mpu_port) { 1084 + case 0: 1085 + case -1: 1086 + break; 1087 + case 0x300: 1088 + mpu_port_bits = 0x03; 1089 + break; 1090 + case 0x310: 1091 + mpu_port_bits = 0x02; 1092 + break; 1093 + case 0x320: 1094 + mpu_port_bits = 0x01; 1095 + break; 1096 + case 0x330: 1097 + mpu_port_bits = 0x00; 1098 + break; 1099 + default: 1100 + snd_printk(KERN_ERR "MPU-401 port 0x%lx not valid\n", 1101 + chip->mpu_port); 1102 + goto __skip_mpu; 1103 + } 1104 + 1105 + switch (chip->mpu_irq) { 1106 + case 5: 1107 + mpu_irq_bits = 0x02; 1108 + break; 1109 + case 7: 1110 + mpu_irq_bits = 0x03; 1111 + break; 1112 + case 9: 1113 + mpu_irq_bits = 0x00; 1114 + break; 1115 + case 10: 1116 + mpu_irq_bits = 0x01; 1117 + break; 1118 + default: 1119 + snd_printk(KERN_ERR "MPU-401 irq # %d not valid\n", 1120 + chip->mpu_irq); 1121 + goto __skip_mpu; 1122 + } 1123 + 1124 + snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 1125 + (chip->mpu_port <= 0) ? 0x00 : 1126 + 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3, 1127 + 0xf8); 1128 + } 1129 + __skip_mpu: 1130 + 1131 + return 0; 1132 + } 1133 + 1134 + static int __init snd_card_miro_detect(struct snd_card *card, struct snd_miro *chip) 1135 + { 1136 + int i, err; 1137 + unsigned char value; 1138 + 1139 + for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) { 1140 + 1141 + if ((err = snd_miro_init(chip, i)) < 0) 1142 + return err; 1143 + 1144 + if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) 1145 + continue; 1146 + 1147 + value = snd_miro_read(chip, OPTi9XX_MC_REG(1)); 1148 + if ((value != 0xff) && (value != inb(chip->mc_base + 1))) 1149 + if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1))) 1150 + return 1; 1151 + 1152 + release_and_free_resource(chip->res_mc_base); 1153 + chip->res_mc_base = NULL; 1154 + 1155 + } 1156 + 1157 + return -ENODEV; 1158 + } 1159 + 1160 + static int __init snd_card_miro_aci_detect(struct snd_card *card, struct snd_miro * miro) 1161 + { 1162 + unsigned char regval; 1163 + int i; 1164 + 1165 + mutex_init(&miro->aci_mutex); 1166 + 1167 + /* get ACI port from OPTi9xx MC 4 */ 1168 + 1169 + miro->mc_base = 0xf8c; 1170 + regval=inb(miro->mc_base + 4); 1171 + miro->aci_port = (regval & 0x10) ? 0x344: 0x354; 1172 + 1173 + if ((miro->res_aci_port = request_region(miro->aci_port, 3, "miro aci")) == NULL) { 1174 + snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n", 1175 + miro->aci_port, miro->aci_port+2); 1176 + return -ENOMEM; 1177 + } 1178 + 1179 + /* force ACI into a known state */ 1180 + for (i = 0; i < 3; i++) 1181 + if (aci_cmd(miro, ACI_ERROR_OP, -1, -1) < 0) { 1182 + snd_card_free(card); 1183 + snd_printk(KERN_ERR "can't force aci into known state.\n"); 1184 + return -ENXIO; 1185 + } 1186 + 1187 + if ((miro->aci_vendor=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0 || 1188 + (miro->aci_product=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0) { 1189 + snd_card_free(card); 1190 + snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n", miro->aci_port); 1191 + return -ENXIO; 1192 + } 1193 + 1194 + if ((miro->aci_version=aci_cmd(miro, ACI_READ_VERSION, -1, -1)) < 0) { 1195 + snd_card_free(card); 1196 + snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n", 1197 + miro->aci_port); 1198 + return -ENXIO; 1199 + } 1200 + 1201 + if (aci_cmd(miro, ACI_INIT, -1, -1) < 0 || 1202 + aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 || 1203 + aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) { 1204 + snd_printk(KERN_ERR "can't initialize aci.\n"); 1205 + return -ENXIO; 1206 + } 1207 + 1208 + return 0; 1209 + } 1210 + 1211 + static void snd_card_miro_free(struct snd_card *card) 1212 + { 1213 + struct snd_miro *miro = card->private_data; 1214 + 1215 + release_and_free_resource(miro->res_aci_port); 1216 + release_and_free_resource(miro->res_mc_base); 1217 + } 1218 + 1219 + static int __init snd_miro_probe(struct platform_device *devptr) 1220 + { 1221 + static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; 1222 + static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1}; 1223 + static int possible_irqs[] = {11, 9, 10, 7, -1}; 1224 + static int possible_mpu_irqs[] = {10, 5, 9, 7, -1}; 1225 + static int possible_dma1s[] = {3, 1, 0, -1}; 1226 + static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}}; 1227 + 1228 + int error; 1229 + struct snd_miro *miro; 1230 + struct snd_cs4231 *codec; 1231 + struct snd_timer *timer; 1232 + struct snd_card *card; 1233 + struct snd_pcm *pcm; 1234 + struct snd_rawmidi *rmidi; 1235 + 1236 + if (!(card = snd_card_new(index, id, THIS_MODULE, 1237 + sizeof(struct snd_miro)))) 1238 + return -ENOMEM; 1239 + 1240 + card->private_free = snd_card_miro_free; 1241 + miro = card->private_data; 1242 + miro->card = card; 1243 + 1244 + if ((error = snd_card_miro_aci_detect(card, miro)) < 0) { 1245 + snd_card_free(card); 1246 + snd_printk(KERN_ERR "unable to detect aci chip\n"); 1247 + return -ENODEV; 1248 + } 1249 + 1250 + /* init proc interface */ 1251 + snd_miro_proc_init(miro); 1252 + 1253 + if ((error = snd_card_miro_detect(card, miro)) < 0) { 1254 + snd_card_free(card); 1255 + snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n"); 1256 + return -ENODEV; 1257 + } 1258 + 1259 + if (! miro->res_mc_base && 1260 + (miro->res_mc_base = request_region(miro->mc_base, miro->mc_base_size, 1261 + "miro (OPTi9xx MC)")) == NULL) { 1262 + snd_card_free(card); 1263 + snd_printk(KERN_ERR "request for OPTI9xx MC failed\n"); 1264 + return -ENOMEM; 1265 + } 1266 + 1267 + miro->wss_base = port; 1268 + miro->fm_port = fm_port; 1269 + miro->mpu_port = mpu_port; 1270 + miro->irq = irq; 1271 + miro->mpu_irq = mpu_irq; 1272 + miro->dma1 = dma1; 1273 + miro->dma2 = dma2; 1274 + 1275 + if (miro->wss_base == SNDRV_AUTO_PORT) { 1276 + if ((miro->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) { 1277 + snd_card_free(card); 1278 + snd_printk(KERN_ERR "unable to find a free WSS port\n"); 1279 + return -EBUSY; 1280 + } 1281 + } 1282 + 1283 + if (miro->mpu_port == SNDRV_AUTO_PORT) { 1284 + if ((miro->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) { 1285 + snd_card_free(card); 1286 + snd_printk(KERN_ERR "unable to find a free MPU401 port\n"); 1287 + return -EBUSY; 1288 + } 1289 + } 1290 + if (miro->irq == SNDRV_AUTO_IRQ) { 1291 + if ((miro->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) { 1292 + snd_card_free(card); 1293 + snd_printk(KERN_ERR "unable to find a free IRQ\n"); 1294 + return -EBUSY; 1295 + } 1296 + } 1297 + if (miro->mpu_irq == SNDRV_AUTO_IRQ) { 1298 + if ((miro->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) { 1299 + snd_card_free(card); 1300 + snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n"); 1301 + return -EBUSY; 1302 + } 1303 + } 1304 + if (miro->dma1 == SNDRV_AUTO_DMA) { 1305 + if ((miro->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) { 1306 + snd_card_free(card); 1307 + snd_printk(KERN_ERR "unable to find a free DMA1\n"); 1308 + return -EBUSY; 1309 + } 1310 + } 1311 + if (miro->dma2 == SNDRV_AUTO_DMA) { 1312 + if ((miro->dma2 = snd_legacy_find_free_dma(possible_dma2s[miro->dma1 % 4])) < 0) { 1313 + snd_card_free(card); 1314 + snd_printk(KERN_ERR "unable to find a free DMA2\n"); 1315 + return -EBUSY; 1316 + } 1317 + } 1318 + 1319 + if ((error = snd_miro_configure(miro))) { 1320 + snd_card_free(card); 1321 + return error; 1322 + } 1323 + 1324 + if ((error = snd_cs4231_create(card, miro->wss_base + 4, -1, 1325 + miro->irq, miro->dma1, miro->dma2, 1326 + CS4231_HW_AD1845, 1327 + 0, 1328 + &codec)) < 0) { 1329 + snd_card_free(card); 1330 + return error; 1331 + } 1332 + 1333 + if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) { 1334 + snd_card_free(card); 1335 + return error; 1336 + } 1337 + if ((error = snd_cs4231_mixer(codec)) < 0) { 1338 + snd_card_free(card); 1339 + return error; 1340 + } 1341 + if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) { 1342 + snd_card_free(card); 1343 + return error; 1344 + } 1345 + 1346 + miro->pcm = pcm; 1347 + 1348 + if ((error = snd_miro_mixer(miro)) < 0) { 1349 + snd_card_free(card); 1350 + return error; 1351 + } 1352 + 1353 + if (miro->aci_vendor == 'm') { 1354 + /* It looks like a miro sound card. */ 1355 + switch (miro->aci_product) { 1356 + case 'A': 1357 + sprintf(card->shortname, 1358 + "miroSOUND PCM1 pro / PCM12"); 1359 + break; 1360 + case 'B': 1361 + sprintf(card->shortname, 1362 + "miroSOUND PCM12"); 1363 + break; 1364 + case 'C': 1365 + sprintf(card->shortname, 1366 + "miroSOUND PCM20 radio"); 1367 + break; 1368 + default: 1369 + sprintf(card->shortname, 1370 + "unknown miro"); 1371 + snd_printk(KERN_INFO "unknown miro aci id\n"); 1372 + break; 1373 + } 1374 + } else { 1375 + snd_printk(KERN_INFO "found unsupported aci card\n"); 1376 + sprintf(card->shortname, "unknown Cardinal Technologies"); 1377 + } 1378 + 1379 + strcpy(card->driver, "miro"); 1380 + sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d", 1381 + card->shortname, miro->name, pcm->name, miro->wss_base + 4, 1382 + miro->irq, miro->dma1, miro->dma2); 1383 + 1384 + if (miro->mpu_port <= 0 || miro->mpu_port == SNDRV_AUTO_PORT) 1385 + rmidi = NULL; 1386 + else 1387 + if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 1388 + miro->mpu_port, 0, miro->mpu_irq, SA_INTERRUPT, 1389 + &rmidi))) 1390 + snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", miro->mpu_port); 1391 + 1392 + if (miro->fm_port > 0 && miro->fm_port != SNDRV_AUTO_PORT) { 1393 + struct snd_opl3 *opl3 = NULL; 1394 + struct snd_opl4 *opl4; 1395 + if (snd_opl4_create(card, miro->fm_port, miro->fm_port - 8, 1396 + 2, &opl3, &opl4) < 0) 1397 + snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n", miro->fm_port); 1398 + } 1399 + 1400 + if ((error = snd_set_aci_init_values(miro)) < 0) { 1401 + snd_card_free(card); 1402 + return error; 1403 + } 1404 + 1405 + snd_card_set_dev(card, &devptr->dev); 1406 + 1407 + if ((error = snd_card_register(card))) { 1408 + snd_card_free(card); 1409 + return error; 1410 + } 1411 + 1412 + platform_set_drvdata(devptr, card); 1413 + return 0; 1414 + } 1415 + 1416 + static int __devexit snd_miro_remove(struct platform_device *devptr) 1417 + { 1418 + snd_card_free(platform_get_drvdata(devptr)); 1419 + platform_set_drvdata(devptr, NULL); 1420 + return 0; 1421 + } 1422 + 1423 + static struct platform_driver snd_miro_driver = { 1424 + .probe = snd_miro_probe, 1425 + .remove = __devexit_p(snd_miro_remove), 1426 + /* FIXME: suspend/resume */ 1427 + .driver = { 1428 + .name = DRIVER_NAME 1429 + }, 1430 + }; 1431 + 1432 + static int __init alsa_card_miro_init(void) 1433 + { 1434 + int error; 1435 + 1436 + if ((error = platform_driver_register(&snd_miro_driver)) < 0) 1437 + return error; 1438 + device = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); 1439 + if (! IS_ERR(device)) 1440 + return 0; 1441 + #ifdef MODULE 1442 + printk(KERN_ERR "no miro soundcard found\n"); 1443 + #endif 1444 + platform_driver_unregister(&snd_miro_driver); 1445 + return PTR_ERR(device); 1446 + } 1447 + 1448 + static void __exit alsa_card_miro_exit(void) 1449 + { 1450 + platform_device_unregister(device); 1451 + platform_driver_unregister(&snd_miro_driver); 1452 + } 1453 + 1454 + module_init(alsa_card_miro_init) 1455 + module_exit(alsa_card_miro_exit)
+73
sound/isa/opti9xx/miro.h
···
··· 1 + #ifndef _MIRO_H_ 2 + #define _MIRO_H_ 3 + 4 + #define ACI_REG_COMMAND 0 /* write register offset */ 5 + #define ACI_REG_STATUS 1 /* read register offset */ 6 + #define ACI_REG_BUSY 2 /* busy register offset */ 7 + #define ACI_REG_RDS 2 /* PCM20: RDS register offset */ 8 + #define ACI_MINTIME 500 /* ACI time out limit */ 9 + 10 + #define ACI_SET_MUTE 0x0d 11 + #define ACI_SET_POWERAMP 0x0f 12 + #define ACI_SET_TUNERMUTE 0xa3 13 + #define ACI_SET_TUNERMONO 0xa4 14 + #define ACI_SET_IDE 0xd0 15 + #define ACI_SET_WSS 0xd1 16 + #define ACI_SET_SOLOMODE 0xd2 17 + #define ACI_SET_PREAMP 0x03 18 + #define ACI_GET_PREAMP 0x21 19 + #define ACI_WRITE_TUNE 0xa7 20 + #define ACI_READ_TUNERSTEREO 0xa8 21 + #define ACI_READ_TUNERSTATION 0xa9 22 + #define ACI_READ_VERSION 0xf1 23 + #define ACI_READ_IDCODE 0xf2 24 + #define ACI_INIT 0xff 25 + #define ACI_STATUS 0xf0 26 + #define ACI_S_GENERAL 0x00 27 + #define ACI_ERROR_OP 0xdf 28 + 29 + /* ACI Mixer */ 30 + 31 + /* These are the values for the right channel GET registers. 32 + Add an offset of 0x01 for the left channel register. 33 + (left=right+0x01) */ 34 + 35 + #define ACI_GET_MASTER 0x03 36 + #define ACI_GET_MIC 0x05 37 + #define ACI_GET_LINE 0x07 38 + #define ACI_GET_CD 0x09 39 + #define ACI_GET_SYNTH 0x0b 40 + #define ACI_GET_PCM 0x0d 41 + #define ACI_GET_LINE1 0x10 /* Radio on PCM20 */ 42 + #define ACI_GET_LINE2 0x12 43 + 44 + #define ACI_GET_EQ1 0x22 /* from Bass ... */ 45 + #define ACI_GET_EQ2 0x24 46 + #define ACI_GET_EQ3 0x26 47 + #define ACI_GET_EQ4 0x28 48 + #define ACI_GET_EQ5 0x2a 49 + #define ACI_GET_EQ6 0x2c 50 + #define ACI_GET_EQ7 0x2e /* ... to Treble */ 51 + 52 + /* And these are the values for the right channel SET registers. 53 + For left channel access you have to add an offset of 0x08. 54 + MASTER is an exception, which needs an offset of 0x01 */ 55 + 56 + #define ACI_SET_MASTER 0x00 57 + #define ACI_SET_MIC 0x30 58 + #define ACI_SET_LINE 0x31 59 + #define ACI_SET_CD 0x34 60 + #define ACI_SET_SYNTH 0x33 61 + #define ACI_SET_PCM 0x32 62 + #define ACI_SET_LINE1 0x35 /* Radio on PCM20 */ 63 + #define ACI_SET_LINE2 0x36 64 + 65 + #define ACI_SET_EQ1 0x40 /* from Bass ... */ 66 + #define ACI_SET_EQ2 0x41 67 + #define ACI_SET_EQ3 0x42 68 + #define ACI_SET_EQ4 0x43 69 + #define ACI_SET_EQ5 0x44 70 + #define ACI_SET_EQ6 0x45 71 + #define ACI_SET_EQ7 0x46 /* ... to Treble */ 72 + 73 + #endif /* _MIRO_H_ */
+28 -2
sound/pci/Kconfig
··· 15 To compile this as a module, choose M here: the module 16 will be called snd-ad1889. 17 18 config SND_ALS4000 19 tristate "Avance Logic ALS4000" 20 depends on SND && ISA_DMA_API ··· 207 will be called snd-cs46xx. 208 209 config SND_CS46XX_NEW_DSP 210 - bool "Cirrus Logic (Sound Fusion) New DSP support (EXPERIMENTAL)" 211 - depends on SND_CS46XX && EXPERIMENTAL 212 help 213 Say Y here to use a new DSP image for SPDIF and dual codecs. 214 ··· 478 479 To compile this driver as a module, choose M here: the module 480 will be called snd-pcxhr. 481 482 config SND_RME32 483 tristate "RME Digi32, 32/8, 32 PRO"
··· 15 To compile this as a module, choose M here: the module 16 will be called snd-ad1889. 17 18 + config SND_ALS300 19 + tristate "Avance Logic ALS300/ALS300+" 20 + depends on SND 21 + select SND_PCM 22 + select SND_AC97_CODEC 23 + select SND_OPL3_LIB 24 + help 25 + Say 'Y' or 'M' to include support for Avance Logic ALS300/ALS300+ 26 + 27 + To compile this driver as a module, choose M here: the module 28 + will be called snd-als300 29 + 30 config SND_ALS4000 31 tristate "Avance Logic ALS4000" 32 depends on SND && ISA_DMA_API ··· 195 will be called snd-cs46xx. 196 197 config SND_CS46XX_NEW_DSP 198 + bool "Cirrus Logic (Sound Fusion) New DSP support" 199 + depends on SND_CS46XX 200 + default y 201 help 202 Say Y here to use a new DSP image for SPDIF and dual codecs. 203 ··· 465 466 To compile this driver as a module, choose M here: the module 467 will be called snd-pcxhr. 468 + 469 + config SND_RIPTIDE 470 + tristate "Conexant Riptide" 471 + depends on SND 472 + depends on FW_LOADER 473 + select SND_OPL3_LIB 474 + select SND_MPU401_UART 475 + select SND_AC97_CODEC 476 + help 477 + Say 'Y' or 'M' to include support for Conexant Riptide chip. 478 + 479 + To compile this driver as a module, choose M here: the module 480 + will be called snd-riptide 481 482 config SND_RME32 483 tristate "RME Digi32, 32/8, 32 PRO"
+3
sound/pci/Makefile
··· 4 # 5 6 snd-ad1889-objs := ad1889.o 7 snd-als4000-objs := als4000.o 8 snd-atiixp-objs := atiixp.o 9 snd-atiixp-modem-objs := atiixp_modem.o ··· 28 29 # Toplevel Module Dependency 30 obj-$(CONFIG_SND_AD1889) += snd-ad1889.o 31 obj-$(CONFIG_SND_ALS4000) += snd-als4000.o 32 obj-$(CONFIG_SND_ATIIXP) += snd-atiixp.o 33 obj-$(CONFIG_SND_ATIIXP_MODEM) += snd-atiixp-modem.o ··· 64 mixart/ \ 65 nm256/ \ 66 pcxhr/ \ 67 rme9652/ \ 68 trident/ \ 69 ymfpci/ \
··· 4 # 5 6 snd-ad1889-objs := ad1889.o 7 + snd-als300-objs := als300.o 8 snd-als4000-objs := als4000.o 9 snd-atiixp-objs := atiixp.o 10 snd-atiixp-modem-objs := atiixp_modem.o ··· 27 28 # Toplevel Module Dependency 29 obj-$(CONFIG_SND_AD1889) += snd-ad1889.o 30 + obj-$(CONFIG_SND_ALS300) += snd-als300.o 31 obj-$(CONFIG_SND_ALS4000) += snd-als4000.o 32 obj-$(CONFIG_SND_ATIIXP) += snd-atiixp.o 33 obj-$(CONFIG_SND_ATIIXP_MODEM) += snd-atiixp-modem.o ··· 62 mixart/ \ 63 nm256/ \ 64 pcxhr/ \ 65 + riptide/ \ 66 rme9652/ \ 67 trident/ \ 68 ymfpci/ \
+866
sound/pci/als300.c
···
··· 1 + /* 2 + * als300.c - driver for Avance Logic ALS300/ALS300+ soundcards. 3 + * Copyright (C) 2005 by Ash Willis <ashwillis@programmer.net> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation; either version 2 of the License, or 8 + * (at your option) any later version. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + * 15 + * You should have received a copy of the GNU General Public License 16 + * along with this program; if not, write to the Free Software 17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 + * 19 + * TODO 20 + * 4 channel playback for ALS300+ 21 + * gameport 22 + * mpu401 23 + * opl3 24 + * 25 + * NOTES 26 + * The BLOCK_COUNTER registers for the ALS300(+) return a figure related to 27 + * the position in the current period, NOT the whole buffer. It is important 28 + * to know which period we are in so we can calculate the correct pointer. 29 + * This is why we always use 2 periods. We can then use a flip-flop variable 30 + * to keep track of what period we are in. 31 + */ 32 + 33 + #include <sound/driver.h> 34 + #include <linux/delay.h> 35 + #include <linux/init.h> 36 + #include <linux/moduleparam.h> 37 + #include <linux/pci.h> 38 + #include <linux/interrupt.h> 39 + #include <linux/slab.h> 40 + 41 + #include <asm/io.h> 42 + 43 + #include <sound/core.h> 44 + #include <sound/control.h> 45 + #include <sound/initval.h> 46 + #include <sound/pcm.h> 47 + #include <sound/pcm_params.h> 48 + #include <sound/ac97_codec.h> 49 + #include <sound/opl3.h> 50 + 51 + /* snd_als300_set_irq_flag */ 52 + #define IRQ_DISABLE 0 53 + #define IRQ_ENABLE 1 54 + 55 + /* I/O port layout */ 56 + #define AC97_ACCESS 0x00 57 + #define AC97_READ 0x04 58 + #define AC97_STATUS 0x06 59 + #define AC97_DATA_AVAIL (1<<6) 60 + #define AC97_BUSY (1<<7) 61 + #define ALS300_IRQ_STATUS 0x07 /* ALS300 Only */ 62 + #define IRQ_PLAYBACK (1<<3) 63 + #define IRQ_CAPTURE (1<<2) 64 + #define GCR_DATA 0x08 65 + #define GCR_INDEX 0x0C 66 + #define ALS300P_DRAM_IRQ_STATUS 0x0D /* ALS300+ Only */ 67 + #define MPU_IRQ_STATUS 0x0E /* ALS300 Rev. E+, ALS300+ */ 68 + #define ALS300P_IRQ_STATUS 0x0F /* ALS300+ Only */ 69 + 70 + /* General Control Registers */ 71 + #define PLAYBACK_START 0x80 72 + #define PLAYBACK_END 0x81 73 + #define PLAYBACK_CONTROL 0x82 74 + #define TRANSFER_START (1<<16) 75 + #define FIFO_PAUSE (1<<17) 76 + #define RECORD_START 0x83 77 + #define RECORD_END 0x84 78 + #define RECORD_CONTROL 0x85 79 + #define DRAM_WRITE_CONTROL 0x8B 80 + #define WRITE_TRANS_START (1<<16) 81 + #define DRAM_MODE_2 (1<<17) 82 + #define MISC_CONTROL 0x8C 83 + #define IRQ_SET_BIT (1<<15) 84 + #define VMUTE_NORMAL (1<<20) 85 + #define MMUTE_NORMAL (1<<21) 86 + #define MUS_VOC_VOL 0x8E 87 + #define PLAYBACK_BLOCK_COUNTER 0x9A 88 + #define RECORD_BLOCK_COUNTER 0x9B 89 + 90 + #define DEBUG_CALLS 1 91 + #define DEBUG_PLAY_REC 1 92 + 93 + #if DEBUG_CALLS 94 + #define snd_als300_dbgcalls(format, args...) printk(format, ##args) 95 + #define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__) 96 + #define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__) 97 + #else 98 + #define snd_als300_dbgcalls(format, args...) 99 + #define snd_als300_dbgcallenter() 100 + #define snd_als300_dbgcallleave() 101 + #endif 102 + 103 + #if DEBUG_PLAY_REC 104 + #define snd_als300_dbgplay(format, args...) printk(KERN_ERR format, ##args) 105 + #else 106 + #define snd_als300_dbgplay(format, args...) 107 + #endif 108 + 109 + enum {DEVICE_ALS300, DEVICE_ALS300_PLUS}; 110 + 111 + MODULE_AUTHOR("Ash Willis <ashwillis@programmer.net>"); 112 + MODULE_DESCRIPTION("Avance Logic ALS300"); 113 + MODULE_LICENSE("GPL"); 114 + MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS300},{Avance Logic,ALS300+}}"); 115 + 116 + static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 117 + static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 118 + static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 119 + 120 + struct snd_als300 { 121 + unsigned long port; 122 + spinlock_t reg_lock; 123 + struct snd_card *card; 124 + struct pci_dev *pci; 125 + 126 + struct snd_pcm *pcm; 127 + struct snd_pcm_substream *playback_substream; 128 + struct snd_pcm_substream *capture_substream; 129 + 130 + struct snd_ac97 *ac97; 131 + struct snd_opl3 *opl3; 132 + 133 + struct resource *res_port; 134 + 135 + int irq; 136 + 137 + int chip_type; /* ALS300 or ALS300+ */ 138 + 139 + char revision; 140 + }; 141 + 142 + struct snd_als300_substream_data { 143 + int period_flipflop; 144 + int control_register; 145 + int block_counter_register; 146 + }; 147 + 148 + static struct pci_device_id snd_als300_ids[] = { 149 + { 0x4005, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300 }, 150 + { 0x4005, 0x0308, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300_PLUS }, 151 + { 0, } 152 + }; 153 + 154 + MODULE_DEVICE_TABLE(pci, snd_als300_ids); 155 + 156 + static inline u32 snd_als300_gcr_read(unsigned long port, unsigned short reg) 157 + { 158 + outb(reg, port+GCR_INDEX); 159 + return inl(port+GCR_DATA); 160 + } 161 + 162 + static inline void snd_als300_gcr_write(unsigned long port, 163 + unsigned short reg, u32 val) 164 + { 165 + outb(reg, port+GCR_INDEX); 166 + outl(val, port+GCR_DATA); 167 + } 168 + 169 + /* Enable/Disable Interrupts */ 170 + static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd) 171 + { 172 + u32 tmp = snd_als300_gcr_read(chip->port, MISC_CONTROL); 173 + snd_als300_dbgcallenter(); 174 + 175 + /* boolean XOR check, since old vs. new hardware have 176 + directly reversed bit setting for ENABLE and DISABLE. 177 + ALS300+ acts like newer versions of ALS300 */ 178 + if (((chip->revision > 5 || chip->chip_type == DEVICE_ALS300_PLUS) ^ 179 + (cmd == IRQ_ENABLE)) == 0) 180 + tmp |= IRQ_SET_BIT; 181 + else 182 + tmp &= ~IRQ_SET_BIT; 183 + snd_als300_gcr_write(chip->port, MISC_CONTROL, tmp); 184 + snd_als300_dbgcallleave(); 185 + } 186 + 187 + static int snd_als300_free(struct snd_als300 *chip) 188 + { 189 + snd_als300_dbgcallenter(); 190 + snd_als300_set_irq_flag(chip, IRQ_DISABLE); 191 + if (chip->irq >= 0) 192 + free_irq(chip->irq, (void *)chip); 193 + pci_release_regions(chip->pci); 194 + pci_disable_device(chip->pci); 195 + kfree(chip); 196 + snd_als300_dbgcallleave(); 197 + return 0; 198 + } 199 + 200 + static int snd_als300_dev_free(struct snd_device *device) 201 + { 202 + struct snd_als300 *chip = device->device_data; 203 + return snd_als300_free(chip); 204 + } 205 + 206 + static irqreturn_t snd_als300_interrupt(int irq, void *dev_id, 207 + struct pt_regs *regs) 208 + { 209 + u8 status; 210 + struct snd_als300 *chip = dev_id; 211 + struct snd_als300_substream_data *data; 212 + 213 + status = inb(chip->port+ALS300_IRQ_STATUS); 214 + if (!status) /* shared IRQ, for different device?? Exit ASAP! */ 215 + return IRQ_NONE; 216 + 217 + /* ACK everything ASAP */ 218 + outb(status, chip->port+ALS300_IRQ_STATUS); 219 + if (status & IRQ_PLAYBACK) { 220 + if (chip->pcm && chip->playback_substream) { 221 + data = chip->playback_substream->runtime->private_data; 222 + data->period_flipflop ^= 1; 223 + snd_pcm_period_elapsed(chip->playback_substream); 224 + snd_als300_dbgplay("IRQ_PLAYBACK\n"); 225 + } 226 + } 227 + if (status & IRQ_CAPTURE) { 228 + if (chip->pcm && chip->capture_substream) { 229 + data = chip->capture_substream->runtime->private_data; 230 + data->period_flipflop ^= 1; 231 + snd_pcm_period_elapsed(chip->capture_substream); 232 + snd_als300_dbgplay("IRQ_CAPTURE\n"); 233 + } 234 + } 235 + return IRQ_HANDLED; 236 + } 237 + 238 + static irqreturn_t snd_als300plus_interrupt(int irq, void *dev_id, 239 + struct pt_regs *regs) 240 + { 241 + u8 general, mpu, dram; 242 + struct snd_als300 *chip = dev_id; 243 + struct snd_als300_substream_data *data; 244 + 245 + general = inb(chip->port+ALS300P_IRQ_STATUS); 246 + mpu = inb(chip->port+MPU_IRQ_STATUS); 247 + dram = inb(chip->port+ALS300P_DRAM_IRQ_STATUS); 248 + 249 + /* shared IRQ, for different device?? Exit ASAP! */ 250 + if ((general == 0) && ((mpu & 0x80) == 0) && ((dram & 0x01) == 0)) 251 + return IRQ_NONE; 252 + 253 + if (general & IRQ_PLAYBACK) { 254 + if (chip->pcm && chip->playback_substream) { 255 + outb(IRQ_PLAYBACK, chip->port+ALS300P_IRQ_STATUS); 256 + data = chip->playback_substream->runtime->private_data; 257 + data->period_flipflop ^= 1; 258 + snd_pcm_period_elapsed(chip->playback_substream); 259 + snd_als300_dbgplay("IRQ_PLAYBACK\n"); 260 + } 261 + } 262 + if (general & IRQ_CAPTURE) { 263 + if (chip->pcm && chip->capture_substream) { 264 + outb(IRQ_CAPTURE, chip->port+ALS300P_IRQ_STATUS); 265 + data = chip->capture_substream->runtime->private_data; 266 + data->period_flipflop ^= 1; 267 + snd_pcm_period_elapsed(chip->capture_substream); 268 + snd_als300_dbgplay("IRQ_CAPTURE\n"); 269 + } 270 + } 271 + /* FIXME: Ack other interrupt types. Not important right now as 272 + * those other devices aren't enabled. */ 273 + return IRQ_HANDLED; 274 + } 275 + 276 + static void __devexit snd_als300_remove(struct pci_dev *pci) 277 + { 278 + snd_als300_dbgcallenter(); 279 + snd_card_free(pci_get_drvdata(pci)); 280 + pci_set_drvdata(pci, NULL); 281 + snd_als300_dbgcallleave(); 282 + } 283 + 284 + static unsigned short snd_als300_ac97_read(struct snd_ac97 *ac97, 285 + unsigned short reg) 286 + { 287 + int i; 288 + struct snd_als300 *chip = ac97->private_data; 289 + 290 + for (i = 0; i < 1000; i++) { 291 + if ((inb(chip->port+AC97_STATUS) & (AC97_BUSY)) == 0) 292 + break; 293 + udelay(10); 294 + } 295 + outl((reg << 24) | (1 << 31), chip->port+AC97_ACCESS); 296 + 297 + for (i = 0; i < 1000; i++) { 298 + if ((inb(chip->port+AC97_STATUS) & (AC97_DATA_AVAIL)) != 0) 299 + break; 300 + udelay(10); 301 + } 302 + return inw(chip->port+AC97_READ); 303 + } 304 + 305 + static void snd_als300_ac97_write(struct snd_ac97 *ac97, 306 + unsigned short reg, unsigned short val) 307 + { 308 + int i; 309 + struct snd_als300 *chip = ac97->private_data; 310 + 311 + for (i = 0; i < 1000; i++) { 312 + if ((inb(chip->port+AC97_STATUS) & (AC97_BUSY)) == 0) 313 + break; 314 + udelay(10); 315 + } 316 + outl((reg << 24) | val, chip->port+AC97_ACCESS); 317 + } 318 + 319 + static int snd_als300_ac97(struct snd_als300 *chip) 320 + { 321 + struct snd_ac97_bus *bus; 322 + struct snd_ac97_template ac97; 323 + int err; 324 + static struct snd_ac97_bus_ops ops = { 325 + .write = snd_als300_ac97_write, 326 + .read = snd_als300_ac97_read, 327 + }; 328 + 329 + snd_als300_dbgcallenter(); 330 + if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &bus)) < 0) 331 + return err; 332 + 333 + memset(&ac97, 0, sizeof(ac97)); 334 + ac97.private_data = chip; 335 + 336 + snd_als300_dbgcallleave(); 337 + return snd_ac97_mixer(bus, &ac97, &chip->ac97); 338 + } 339 + 340 + /* hardware definition 341 + * 342 + * In AC97 mode, we always use 48k/16bit/stereo. 343 + * Any request to change data type is ignored by 344 + * the card when it is running outside of legacy 345 + * mode. 346 + */ 347 + static struct snd_pcm_hardware snd_als300_playback_hw = 348 + { 349 + .info = (SNDRV_PCM_INFO_MMAP | 350 + SNDRV_PCM_INFO_INTERLEAVED | 351 + SNDRV_PCM_INFO_PAUSE | 352 + SNDRV_PCM_INFO_MMAP_VALID), 353 + .formats = SNDRV_PCM_FMTBIT_S16, 354 + .rates = SNDRV_PCM_RATE_48000, 355 + .rate_min = 48000, 356 + .rate_max = 48000, 357 + .channels_min = 2, 358 + .channels_max = 2, 359 + .buffer_bytes_max = 64 * 1024, 360 + .period_bytes_min = 64, 361 + .period_bytes_max = 32 * 1024, 362 + .periods_min = 2, 363 + .periods_max = 2, 364 + }; 365 + 366 + static struct snd_pcm_hardware snd_als300_capture_hw = 367 + { 368 + .info = (SNDRV_PCM_INFO_MMAP | 369 + SNDRV_PCM_INFO_INTERLEAVED | 370 + SNDRV_PCM_INFO_PAUSE | 371 + SNDRV_PCM_INFO_MMAP_VALID), 372 + .formats = SNDRV_PCM_FMTBIT_S16, 373 + .rates = SNDRV_PCM_RATE_48000, 374 + .rate_min = 48000, 375 + .rate_max = 48000, 376 + .channels_min = 2, 377 + .channels_max = 2, 378 + .buffer_bytes_max = 64 * 1024, 379 + .period_bytes_min = 64, 380 + .period_bytes_max = 32 * 1024, 381 + .periods_min = 2, 382 + .periods_max = 2, 383 + }; 384 + 385 + static int snd_als300_playback_open(struct snd_pcm_substream *substream) 386 + { 387 + struct snd_als300 *chip = snd_pcm_substream_chip(substream); 388 + struct snd_pcm_runtime *runtime = substream->runtime; 389 + struct snd_als300_substream_data *data = kzalloc(sizeof(*data), 390 + GFP_KERNEL); 391 + 392 + snd_als300_dbgcallenter(); 393 + chip->playback_substream = substream; 394 + runtime->hw = snd_als300_playback_hw; 395 + runtime->private_data = data; 396 + data->control_register = PLAYBACK_CONTROL; 397 + data->block_counter_register = PLAYBACK_BLOCK_COUNTER; 398 + snd_als300_dbgcallleave(); 399 + return 0; 400 + } 401 + 402 + static int snd_als300_playback_close(struct snd_pcm_substream *substream) 403 + { 404 + struct snd_als300 *chip = snd_pcm_substream_chip(substream); 405 + struct snd_als300_substream_data *data; 406 + 407 + data = substream->runtime->private_data; 408 + snd_als300_dbgcallenter(); 409 + kfree(data); 410 + chip->playback_substream = NULL; 411 + snd_pcm_lib_free_pages(substream); 412 + snd_als300_dbgcallleave(); 413 + return 0; 414 + } 415 + 416 + static int snd_als300_capture_open(struct snd_pcm_substream *substream) 417 + { 418 + struct snd_als300 *chip = snd_pcm_substream_chip(substream); 419 + struct snd_pcm_runtime *runtime = substream->runtime; 420 + struct snd_als300_substream_data *data = kzalloc(sizeof(*data), 421 + GFP_KERNEL); 422 + 423 + snd_als300_dbgcallenter(); 424 + chip->capture_substream = substream; 425 + runtime->hw = snd_als300_capture_hw; 426 + runtime->private_data = data; 427 + data->control_register = RECORD_CONTROL; 428 + data->block_counter_register = RECORD_BLOCK_COUNTER; 429 + snd_als300_dbgcallleave(); 430 + return 0; 431 + } 432 + 433 + static int snd_als300_capture_close(struct snd_pcm_substream *substream) 434 + { 435 + struct snd_als300 *chip = snd_pcm_substream_chip(substream); 436 + struct snd_als300_substream_data *data; 437 + 438 + data = substream->runtime->private_data; 439 + snd_als300_dbgcallenter(); 440 + kfree(data); 441 + chip->capture_substream = NULL; 442 + snd_pcm_lib_free_pages(substream); 443 + snd_als300_dbgcallleave(); 444 + return 0; 445 + } 446 + 447 + static int snd_als300_pcm_hw_params(struct snd_pcm_substream *substream, 448 + snd_pcm_hw_params_t * hw_params) 449 + { 450 + return snd_pcm_lib_malloc_pages(substream, 451 + params_buffer_bytes(hw_params)); 452 + } 453 + 454 + static int snd_als300_pcm_hw_free(struct snd_pcm_substream *substream) 455 + { 456 + return snd_pcm_lib_free_pages(substream); 457 + } 458 + 459 + static int snd_als300_playback_prepare(struct snd_pcm_substream *substream) 460 + { 461 + u32 tmp; 462 + struct snd_als300 *chip = snd_pcm_substream_chip(substream); 463 + struct snd_pcm_runtime *runtime = substream->runtime; 464 + unsigned short period_bytes = snd_pcm_lib_period_bytes(substream); 465 + unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream); 466 + 467 + snd_als300_dbgcallenter(); 468 + spin_lock_irq(&chip->reg_lock); 469 + tmp = snd_als300_gcr_read(chip->port, PLAYBACK_CONTROL); 470 + tmp &= ~TRANSFER_START; 471 + 472 + snd_als300_dbgplay("Period bytes: %d Buffer bytes %d\n", 473 + period_bytes, buffer_bytes); 474 + 475 + /* set block size */ 476 + tmp &= 0xffff0000; 477 + tmp |= period_bytes - 1; 478 + snd_als300_gcr_write(chip->port, PLAYBACK_CONTROL, tmp); 479 + 480 + /* set dma area */ 481 + snd_als300_gcr_write(chip->port, PLAYBACK_START, 482 + runtime->dma_addr); 483 + snd_als300_gcr_write(chip->port, PLAYBACK_END, 484 + runtime->dma_addr + buffer_bytes - 1); 485 + spin_unlock_irq(&chip->reg_lock); 486 + snd_als300_dbgcallleave(); 487 + return 0; 488 + } 489 + 490 + static int snd_als300_capture_prepare(struct snd_pcm_substream *substream) 491 + { 492 + u32 tmp; 493 + struct snd_als300 *chip = snd_pcm_substream_chip(substream); 494 + struct snd_pcm_runtime *runtime = substream->runtime; 495 + unsigned short period_bytes = snd_pcm_lib_period_bytes(substream); 496 + unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream); 497 + 498 + snd_als300_dbgcallenter(); 499 + spin_lock_irq(&chip->reg_lock); 500 + tmp = snd_als300_gcr_read(chip->port, RECORD_CONTROL); 501 + tmp &= ~TRANSFER_START; 502 + 503 + snd_als300_dbgplay("Period bytes: %d Buffer bytes %d\n", period_bytes, 504 + buffer_bytes); 505 + 506 + /* set block size */ 507 + tmp &= 0xffff0000; 508 + tmp |= period_bytes - 1; 509 + 510 + /* set dma area */ 511 + snd_als300_gcr_write(chip->port, RECORD_CONTROL, tmp); 512 + snd_als300_gcr_write(chip->port, RECORD_START, 513 + runtime->dma_addr); 514 + snd_als300_gcr_write(chip->port, RECORD_END, 515 + runtime->dma_addr + buffer_bytes - 1); 516 + spin_unlock_irq(&chip->reg_lock); 517 + snd_als300_dbgcallleave(); 518 + return 0; 519 + } 520 + 521 + static int snd_als300_trigger(struct snd_pcm_substream *substream, int cmd) 522 + { 523 + struct snd_als300 *chip = snd_pcm_substream_chip(substream); 524 + u32 tmp; 525 + struct snd_als300_substream_data *data; 526 + unsigned short reg; 527 + int ret = 0; 528 + 529 + data = substream->runtime->private_data; 530 + reg = data->control_register; 531 + 532 + snd_als300_dbgcallenter(); 533 + spin_lock(&chip->reg_lock); 534 + switch (cmd) { 535 + case SNDRV_PCM_TRIGGER_START: 536 + case SNDRV_PCM_TRIGGER_RESUME: 537 + tmp = snd_als300_gcr_read(chip->port, reg); 538 + data->period_flipflop = 1; 539 + snd_als300_gcr_write(chip->port, reg, tmp | TRANSFER_START); 540 + snd_als300_dbgplay("TRIGGER START\n"); 541 + break; 542 + case SNDRV_PCM_TRIGGER_STOP: 543 + case SNDRV_PCM_TRIGGER_SUSPEND: 544 + tmp = snd_als300_gcr_read(chip->port, reg); 545 + snd_als300_gcr_write(chip->port, reg, tmp & ~TRANSFER_START); 546 + snd_als300_dbgplay("TRIGGER STOP\n"); 547 + break; 548 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 549 + tmp = snd_als300_gcr_read(chip->port, reg); 550 + snd_als300_gcr_write(chip->port, reg, tmp | FIFO_PAUSE); 551 + snd_als300_dbgplay("TRIGGER PAUSE\n"); 552 + break; 553 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 554 + tmp = snd_als300_gcr_read(chip->port, reg); 555 + snd_als300_gcr_write(chip->port, reg, tmp & ~FIFO_PAUSE); 556 + snd_als300_dbgplay("TRIGGER RELEASE\n"); 557 + break; 558 + default: 559 + snd_als300_dbgplay("TRIGGER INVALID\n"); 560 + ret = -EINVAL; 561 + } 562 + spin_unlock(&chip->reg_lock); 563 + snd_als300_dbgcallleave(); 564 + return ret; 565 + } 566 + 567 + static snd_pcm_uframes_t snd_als300_pointer(struct snd_pcm_substream *substream) 568 + { 569 + u16 current_ptr; 570 + struct snd_als300 *chip = snd_pcm_substream_chip(substream); 571 + struct snd_als300_substream_data *data; 572 + unsigned short period_bytes; 573 + 574 + data = substream->runtime->private_data; 575 + period_bytes = snd_pcm_lib_period_bytes(substream); 576 + 577 + snd_als300_dbgcallenter(); 578 + spin_lock(&chip->reg_lock); 579 + current_ptr = (u16) snd_als300_gcr_read(chip->port, 580 + data->block_counter_register) + 4; 581 + spin_unlock(&chip->reg_lock); 582 + if (current_ptr > period_bytes) 583 + current_ptr = 0; 584 + else 585 + current_ptr = period_bytes - current_ptr; 586 + 587 + if (data->period_flipflop == 0) 588 + current_ptr += period_bytes; 589 + snd_als300_dbgplay("Pointer (bytes): %d\n", current_ptr); 590 + snd_als300_dbgcallleave(); 591 + return bytes_to_frames(substream->runtime, current_ptr); 592 + } 593 + 594 + static struct snd_pcm_ops snd_als300_playback_ops = { 595 + .open = snd_als300_playback_open, 596 + .close = snd_als300_playback_close, 597 + .ioctl = snd_pcm_lib_ioctl, 598 + .hw_params = snd_als300_pcm_hw_params, 599 + .hw_free = snd_als300_pcm_hw_free, 600 + .prepare = snd_als300_playback_prepare, 601 + .trigger = snd_als300_trigger, 602 + .pointer = snd_als300_pointer, 603 + }; 604 + 605 + static struct snd_pcm_ops snd_als300_capture_ops = { 606 + .open = snd_als300_capture_open, 607 + .close = snd_als300_capture_close, 608 + .ioctl = snd_pcm_lib_ioctl, 609 + .hw_params = snd_als300_pcm_hw_params, 610 + .hw_free = snd_als300_pcm_hw_free, 611 + .prepare = snd_als300_capture_prepare, 612 + .trigger = snd_als300_trigger, 613 + .pointer = snd_als300_pointer, 614 + }; 615 + 616 + static int __devinit snd_als300_new_pcm(struct snd_als300 *chip) 617 + { 618 + struct snd_pcm *pcm; 619 + int err; 620 + 621 + snd_als300_dbgcallenter(); 622 + err = snd_pcm_new(chip->card, "ALS300", 0, 1, 1, &pcm); 623 + if (err < 0) 624 + return err; 625 + pcm->private_data = chip; 626 + strcpy(pcm->name, "ALS300"); 627 + chip->pcm = pcm; 628 + 629 + /* set operators */ 630 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, 631 + &snd_als300_playback_ops); 632 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 633 + &snd_als300_capture_ops); 634 + 635 + /* pre-allocation of buffers */ 636 + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 637 + snd_dma_pci_data(chip->pci), 64*1024, 64*1024); 638 + snd_als300_dbgcallleave(); 639 + return 0; 640 + } 641 + 642 + static void snd_als300_init(struct snd_als300 *chip) 643 + { 644 + unsigned long flags; 645 + u32 tmp; 646 + 647 + snd_als300_dbgcallenter(); 648 + spin_lock_irqsave(&chip->reg_lock, flags); 649 + chip->revision = (snd_als300_gcr_read(chip->port, MISC_CONTROL) >> 16) 650 + & 0x0000000F; 651 + /* Setup DRAM */ 652 + tmp = snd_als300_gcr_read(chip->port, DRAM_WRITE_CONTROL); 653 + snd_als300_gcr_write(chip->port, DRAM_WRITE_CONTROL, 654 + (tmp | DRAM_MODE_2) 655 + & ~WRITE_TRANS_START); 656 + 657 + /* Enable IRQ output */ 658 + snd_als300_set_irq_flag(chip, IRQ_ENABLE); 659 + 660 + /* Unmute hardware devices so their outputs get routed to 661 + * the onboard mixer */ 662 + tmp = snd_als300_gcr_read(chip->port, MISC_CONTROL); 663 + snd_als300_gcr_write(chip->port, MISC_CONTROL, 664 + tmp | VMUTE_NORMAL | MMUTE_NORMAL); 665 + 666 + /* Reset volumes */ 667 + snd_als300_gcr_write(chip->port, MUS_VOC_VOL, 0); 668 + 669 + /* Make sure playback transfer is stopped */ 670 + tmp = snd_als300_gcr_read(chip->port, PLAYBACK_CONTROL); 671 + snd_als300_gcr_write(chip->port, PLAYBACK_CONTROL, 672 + tmp & ~TRANSFER_START); 673 + spin_unlock_irqrestore(&chip->reg_lock, flags); 674 + snd_als300_dbgcallleave(); 675 + } 676 + 677 + static int __devinit snd_als300_create(snd_card_t *card, 678 + struct pci_dev *pci, int chip_type, 679 + struct snd_als300 **rchip) 680 + { 681 + struct snd_als300 *chip; 682 + void *irq_handler; 683 + int err; 684 + 685 + static snd_device_ops_t ops = { 686 + .dev_free = snd_als300_dev_free, 687 + }; 688 + *rchip = NULL; 689 + 690 + snd_als300_dbgcallenter(); 691 + if ((err = pci_enable_device(pci)) < 0) 692 + return err; 693 + 694 + if (pci_set_dma_mask(pci, 0x0fffffff) < 0 || 695 + pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) { 696 + printk(KERN_ERR "error setting 28bit DMA mask\n"); 697 + pci_disable_device(pci); 698 + return -ENXIO; 699 + } 700 + pci_set_master(pci); 701 + 702 + chip = kzalloc(sizeof(*chip), GFP_KERNEL); 703 + if (chip == NULL) { 704 + pci_disable_device(pci); 705 + return -ENOMEM; 706 + } 707 + 708 + chip->card = card; 709 + chip->pci = pci; 710 + chip->irq = -1; 711 + chip->chip_type = chip_type; 712 + spin_lock_init(&chip->reg_lock); 713 + 714 + if ((err = pci_request_regions(pci, "ALS300")) < 0) { 715 + kfree(chip); 716 + pci_disable_device(pci); 717 + return err; 718 + } 719 + chip->port = pci_resource_start(pci, 0); 720 + 721 + if (chip->chip_type == DEVICE_ALS300_PLUS) 722 + irq_handler = snd_als300plus_interrupt; 723 + else 724 + irq_handler = snd_als300_interrupt; 725 + 726 + if (request_irq(pci->irq, irq_handler, SA_INTERRUPT|SA_SHIRQ, 727 + card->shortname, (void *)chip)) { 728 + snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 729 + snd_als300_free(chip); 730 + return -EBUSY; 731 + } 732 + chip->irq = pci->irq; 733 + 734 + 735 + snd_als300_init(chip); 736 + 737 + if (snd_als300_ac97(chip) < 0) { 738 + snd_printk(KERN_WARNING "Could not create ac97\n"); 739 + snd_als300_free(chip); 740 + return err; 741 + } 742 + 743 + if ((err = snd_als300_new_pcm(chip)) < 0) { 744 + snd_printk(KERN_WARNING "Could not create PCM\n"); 745 + snd_als300_free(chip); 746 + return err; 747 + } 748 + 749 + if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, 750 + chip, &ops)) < 0) { 751 + snd_als300_free(chip); 752 + return err; 753 + } 754 + 755 + snd_card_set_dev(card, &pci->dev); 756 + 757 + *rchip = chip; 758 + snd_als300_dbgcallleave(); 759 + return 0; 760 + } 761 + 762 + #ifdef CONFIG_PM 763 + static int snd_als300_suspend(struct pci_dev *pci, pm_message_t state) 764 + { 765 + struct snd_card *card = pci_get_drvdata(pci); 766 + struct snd_als300 *chip = card->private_data; 767 + 768 + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 769 + snd_pcm_suspend_all(chip->pcm); 770 + snd_ac97_suspend(chip->ac97); 771 + 772 + pci_set_power_state(pci, PCI_D3hot); 773 + pci_disable_device(pci); 774 + pci_save_state(pci); 775 + return 0; 776 + } 777 + 778 + static int snd_als300_resume(struct pci_dev *pci) 779 + { 780 + struct snd_card *card = pci_get_drvdata(pci); 781 + struct snd_als300 *chip = card->private_data; 782 + 783 + pci_restore_state(pci); 784 + pci_enable_device(pci); 785 + pci_set_power_state(pci, PCI_D0); 786 + pci_set_master(pci); 787 + 788 + snd_als300_init(chip); 789 + snd_ac97_resume(chip->ac97); 790 + 791 + snd_power_change_state(card, SNDRV_CTL_POWER_D0); 792 + return 0; 793 + } 794 + #endif 795 + 796 + static int __devinit snd_als300_probe(struct pci_dev *pci, 797 + const struct pci_device_id *pci_id) 798 + { 799 + static int dev; 800 + struct snd_card *card; 801 + struct snd_als300 *chip; 802 + int err, chip_type; 803 + 804 + if (dev >= SNDRV_CARDS) 805 + return -ENODEV; 806 + if (!enable[dev]) { 807 + dev++; 808 + return -ENOENT; 809 + } 810 + 811 + card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 812 + 813 + if (card == NULL) 814 + return -ENOMEM; 815 + 816 + chip_type = pci_id->driver_data; 817 + 818 + if ((err = snd_als300_create(card, pci, chip_type, &chip)) < 0) { 819 + snd_card_free(card); 820 + return err; 821 + } 822 + card->private_data = chip; 823 + 824 + strcpy(card->driver, "ALS300"); 825 + if (chip->chip_type == DEVICE_ALS300_PLUS) 826 + /* don't know much about ALS300+ yet 827 + * print revision number for now */ 828 + sprintf(card->shortname, "ALS300+ (Rev. %d)", chip->revision); 829 + else 830 + sprintf(card->shortname, "ALS300 (Rev. %c)", 'A' + 831 + chip->revision - 1); 832 + sprintf(card->longname, "%s at 0x%lx irq %i", 833 + card->shortname, chip->port, chip->irq); 834 + 835 + if ((err = snd_card_register(card)) < 0) { 836 + snd_card_free(card); 837 + return err; 838 + } 839 + pci_set_drvdata(pci, card); 840 + dev++; 841 + return 0; 842 + } 843 + 844 + static struct pci_driver driver = { 845 + .name = "ALS300", 846 + .id_table = snd_als300_ids, 847 + .probe = snd_als300_probe, 848 + .remove = __devexit_p(snd_als300_remove), 849 + #ifdef CONFIG_PM 850 + .suspend = snd_als300_suspend, 851 + .resume = snd_als300_resume, 852 + #endif 853 + }; 854 + 855 + static int __init alsa_card_als300_init(void) 856 + { 857 + return pci_register_driver(&driver); 858 + } 859 + 860 + static void __exit alsa_card_als300_exit(void) 861 + { 862 + pci_unregister_driver(&driver); 863 + } 864 + 865 + module_init(alsa_card_als300_init) 866 + module_exit(alsa_card_als300_exit)
+14 -14
sound/pci/cs4281.c
··· 1046 snd_cs4281_pokeBA0(chip, regL, volL); 1047 change = 1; 1048 } 1049 - if (ucontrol->value.integer.value[0] != volL) { 1050 volR = CS_VOL_MASK - (ucontrol->value.integer.value[1] & CS_VOL_MASK); 1051 snd_cs4281_pokeBA0(chip, regR, volR); 1052 change = 1; ··· 1416 static int snd_cs4281_chip_init(struct cs4281 *chip) 1417 { 1418 unsigned int tmp; 1419 - int timeout; 1420 int retry_count = 2; 1421 1422 /* Having EPPMC.FPDN=1 prevent proper chip initialisation */ ··· 1496 /* 1497 * Wait for the DLL ready signal from the clock logic. 1498 */ 1499 - timeout = 100; 1500 do { 1501 /* 1502 * Read the AC97 status register to see if we've seen a CODEC ··· 1504 */ 1505 if (snd_cs4281_peekBA0(chip, BA0_CLKCR1) & BA0_CLKCR1_DLLRDY) 1506 goto __ok0; 1507 - msleep(1); 1508 - } while (timeout-- > 0); 1509 1510 snd_printk(KERN_ERR "DLLRDY not seen\n"); 1511 return -EIO; ··· 1522 /* 1523 * Wait for the codec ready signal from the AC97 codec. 1524 */ 1525 - timeout = 100; 1526 do { 1527 /* 1528 * Read the AC97 status register to see if we've seen a CODEC ··· 1530 */ 1531 if (snd_cs4281_peekBA0(chip, BA0_ACSTS) & BA0_ACSTS_CRDY) 1532 goto __ok1; 1533 - msleep(1); 1534 - } while (timeout-- > 0); 1535 1536 snd_printk(KERN_ERR "never read codec ready from AC'97 (0x%x)\n", snd_cs4281_peekBA0(chip, BA0_ACSTS)); 1537 return -EIO; 1538 1539 __ok1: 1540 if (chip->dual_codec) { 1541 - timeout = 100; 1542 do { 1543 if (snd_cs4281_peekBA0(chip, BA0_ACSTS2) & BA0_ACSTS_CRDY) 1544 goto __codec2_ok; 1545 - msleep(1); 1546 - } while (timeout-- > 0); 1547 snd_printk(KERN_INFO "secondary codec doesn't respond. disable it...\n"); 1548 chip->dual_codec = 0; 1549 __codec2_ok: ; ··· 1561 * the codec is pumping ADC data across the AC-link. 1562 */ 1563 1564 - timeout = 100; 1565 do { 1566 /* 1567 * Read the input slot valid register and see if input slots 3 ··· 1569 */ 1570 if ((snd_cs4281_peekBA0(chip, BA0_ACISV) & (BA0_ACISV_SLV(3) | BA0_ACISV_SLV(4))) == (BA0_ACISV_SLV(3) | BA0_ACISV_SLV(4))) 1571 goto __ok2; 1572 - msleep(1); 1573 - } while (timeout-- > 0); 1574 1575 if (--retry_count > 0) 1576 goto __retry;
··· 1046 snd_cs4281_pokeBA0(chip, regL, volL); 1047 change = 1; 1048 } 1049 + if (ucontrol->value.integer.value[1] != volR) { 1050 volR = CS_VOL_MASK - (ucontrol->value.integer.value[1] & CS_VOL_MASK); 1051 snd_cs4281_pokeBA0(chip, regR, volR); 1052 change = 1; ··· 1416 static int snd_cs4281_chip_init(struct cs4281 *chip) 1417 { 1418 unsigned int tmp; 1419 + unsigned long end_time; 1420 int retry_count = 2; 1421 1422 /* Having EPPMC.FPDN=1 prevent proper chip initialisation */ ··· 1496 /* 1497 * Wait for the DLL ready signal from the clock logic. 1498 */ 1499 + end_time = jiffies + HZ; 1500 do { 1501 /* 1502 * Read the AC97 status register to see if we've seen a CODEC ··· 1504 */ 1505 if (snd_cs4281_peekBA0(chip, BA0_CLKCR1) & BA0_CLKCR1_DLLRDY) 1506 goto __ok0; 1507 + schedule_timeout_uninterruptible(1); 1508 + } while (time_after_eq(end_time, jiffies)); 1509 1510 snd_printk(KERN_ERR "DLLRDY not seen\n"); 1511 return -EIO; ··· 1522 /* 1523 * Wait for the codec ready signal from the AC97 codec. 1524 */ 1525 + end_time = jiffies + HZ; 1526 do { 1527 /* 1528 * Read the AC97 status register to see if we've seen a CODEC ··· 1530 */ 1531 if (snd_cs4281_peekBA0(chip, BA0_ACSTS) & BA0_ACSTS_CRDY) 1532 goto __ok1; 1533 + schedule_timeout_uninterruptible(1); 1534 + } while (time_after_eq(end_time, jiffies)); 1535 1536 snd_printk(KERN_ERR "never read codec ready from AC'97 (0x%x)\n", snd_cs4281_peekBA0(chip, BA0_ACSTS)); 1537 return -EIO; 1538 1539 __ok1: 1540 if (chip->dual_codec) { 1541 + end_time = jiffies + HZ; 1542 do { 1543 if (snd_cs4281_peekBA0(chip, BA0_ACSTS2) & BA0_ACSTS_CRDY) 1544 goto __codec2_ok; 1545 + schedule_timeout_uninterruptible(1); 1546 + } while (time_after_eq(end_time, jiffies)); 1547 snd_printk(KERN_INFO "secondary codec doesn't respond. disable it...\n"); 1548 chip->dual_codec = 0; 1549 __codec2_ok: ; ··· 1561 * the codec is pumping ADC data across the AC-link. 1562 */ 1563 1564 + end_time = jiffies + HZ; 1565 do { 1566 /* 1567 * Read the input slot valid register and see if input slots 3 ··· 1569 */ 1570 if ((snd_cs4281_peekBA0(chip, BA0_ACISV) & (BA0_ACISV_SLV(3) | BA0_ACISV_SLV(4))) == (BA0_ACISV_SLV(3) | BA0_ACISV_SLV(4))) 1571 goto __ok2; 1572 + schedule_timeout_uninterruptible(1); 1573 + } while (time_after_eq(end_time, jiffies)); 1574 1575 if (--retry_count > 0) 1576 goto __retry;
+1 -1
sound/pci/hda/hda_codec.c
··· 295 snd_printk(KERN_ERR "hda_codec: can't allocate unsolicited queue\n"); 296 return -ENOMEM; 297 } 298 - unsol->workq = create_workqueue("hda_codec"); 299 if (! unsol->workq) { 300 snd_printk(KERN_ERR "hda_codec: can't create workqueue\n"); 301 kfree(unsol);
··· 295 snd_printk(KERN_ERR "hda_codec: can't allocate unsolicited queue\n"); 296 return -ENOMEM; 297 } 298 + unsol->workq = create_singlethread_workqueue("hda_codec"); 299 if (! unsol->workq) { 300 snd_printk(KERN_ERR "hda_codec: can't create workqueue\n"); 301 kfree(unsol);
+2
sound/pci/hda/hda_intel.c
··· 81 "{Intel, ESB2}," 82 "{Intel, ICH8}," 83 "{ATI, SB450}," 84 "{VIA, VT8251}," 85 "{VIA, VT8237A}," 86 "{SiS, SIS966}," ··· 1620 { 0x8086, 0x269a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ESB2 */ 1621 { 0x8086, 0x284b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH8 */ 1622 { 0x1002, 0x437b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATI }, /* ATI SB450 */ 1623 { 0x1106, 0x3288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_VIA }, /* VIA VT8251/VT8237A */ 1624 { 0x1039, 0x7502, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SIS }, /* SIS966 */ 1625 { 0x10b9, 0x5461, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ULI }, /* ULI M5461 */
··· 81 "{Intel, ESB2}," 82 "{Intel, ICH8}," 83 "{ATI, SB450}," 84 + "{ATI, SB600}," 85 "{VIA, VT8251}," 86 "{VIA, VT8237A}," 87 "{SiS, SIS966}," ··· 1619 { 0x8086, 0x269a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ESB2 */ 1620 { 0x8086, 0x284b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH8 */ 1621 { 0x1002, 0x437b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATI }, /* ATI SB450 */ 1622 + { 0x1002, 0x4383, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATI }, /* ATI SB600 */ 1623 { 0x1106, 0x3288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_VIA }, /* VIA VT8251/VT8237A */ 1624 { 0x1039, 0x7502, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SIS }, /* SIS966 */ 1625 { 0x10b9, 0x5461, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ULI }, /* ULI M5461 */
+8 -1
sound/pci/hda/patch_analog.c
··· 44 * dig_out_nid and hp_nid are optional 45 */ 46 unsigned int cur_eapd; 47 48 /* capture */ 49 unsigned int num_adc_nids; ··· 837 case AD1986A_3STACK: 838 spec->num_mixers = 2; 839 spec->mixers[1] = ad1986a_3st_mixers; 840 - spec->num_init_verbs = 2; 841 spec->init_verbs[1] = ad1986a_3st_init_verbs; 842 spec->channel_mode = ad1986a_modes; 843 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes); 844 break; 845 case AD1986A_LAPTOP: 846 spec->mixers[0] = ad1986a_laptop_mixers; ··· 1560 { 1561 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1562 struct ad198x_spec *spec = codec->spec; 1563 return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 1564 spec->num_channel_mode, &spec->multiout.max_channels); 1565 }
··· 44 * dig_out_nid and hp_nid are optional 45 */ 46 unsigned int cur_eapd; 47 + unsigned int need_dac_fix; 48 49 /* capture */ 50 unsigned int num_adc_nids; ··· 836 case AD1986A_3STACK: 837 spec->num_mixers = 2; 838 spec->mixers[1] = ad1986a_3st_mixers; 839 + spec->num_init_verbs = 3; 840 spec->init_verbs[1] = ad1986a_3st_init_verbs; 841 + spec->init_verbs[2] = ad1986a_ch2_init; 842 spec->channel_mode = ad1986a_modes; 843 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes); 844 + spec->need_dac_fix = 1; 845 + spec->multiout.max_channels = 2; 846 + spec->multiout.num_dacs = 1; 847 break; 848 case AD1986A_LAPTOP: 849 spec->mixers[0] = ad1986a_laptop_mixers; ··· 1555 { 1556 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1557 struct ad198x_spec *spec = codec->spec; 1558 + if (spec->need_dac_fix) 1559 + spec->multiout.num_dacs = spec->multiout.max_channels / 2; 1560 return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, 1561 spec->num_channel_mode, &spec->multiout.max_channels); 1562 }
+242 -56
sound/pci/hda/patch_realtek.c
··· 52 ALC880_CLEVO, 53 ALC880_TCL_S700, 54 ALC880_LG, 55 #ifdef CONFIG_SND_DEBUG 56 ALC880_TEST, 57 #endif ··· 132 hda_nid_t dig_in_nid; /* digital-in NID; optional */ 133 134 /* capture source */ 135 const struct hda_input_mux *input_mux; 136 unsigned int cur_mux[3]; 137 ··· 174 hda_nid_t dig_in_nid; 175 unsigned int num_channel_mode; 176 const struct hda_channel_mode *channel_mode; 177 const struct hda_input_mux *input_mux; 178 void (*unsol_event)(struct hda_codec *, unsigned int); 179 void (*init_hook)(struct hda_codec *); ··· 188 { 189 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 190 struct alc_spec *spec = codec->spec; 191 - return snd_hda_input_mux_info(spec->input_mux, uinfo); 192 } 193 194 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) ··· 209 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 210 struct alc_spec *spec = codec->spec; 211 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 212 - return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 213 spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]); 214 } 215 ··· 252 * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these 253 * are requested. Therefore order this list so that this behaviour will not 254 * cause problems when mixer clients move through the enum sequentially. 255 - * NIDs 0x0f and 0x10 have been observed to have this behaviour. 256 */ 257 static char *alc_pin_mode_names[] = { 258 "Mic 50pc bias", "Mic 80pc bias", ··· 263 PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP, 264 }; 265 /* The control can present all 5 options, or it can limit the options based 266 - * in the pin being assumed to be exclusively an input or an output pin. 267 */ 268 - #define ALC_PIN_DIR_IN 0x00 269 - #define ALC_PIN_DIR_OUT 0x01 270 - #define ALC_PIN_DIR_INOUT 0x02 271 272 - /* Info about the pin modes supported by the three different pin directions. 273 * For each direction the minimum and maximum values are given. 274 */ 275 - static signed char alc_pin_mode_dir_info[3][2] = { 276 { 0, 2 }, /* ALC_PIN_DIR_IN */ 277 { 3, 4 }, /* ALC_PIN_DIR_OUT */ 278 { 0, 4 }, /* ALC_PIN_DIR_INOUT */ 279 }; 280 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0]) 281 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1]) ··· 345 * input modes. 346 * 347 * Dynamically switching the input/output buffers probably 348 - * reduces noise slightly, particularly on input. However, 349 - * havingboth input and output buffers enabled 350 - * simultaneously doesn't seem to be problematic. 351 */ 352 if (val <= 2) { 353 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE, ··· 500 spec->multiout.dig_out_nid = preset->dig_out_nid; 501 spec->multiout.hp_nid = preset->hp_nid; 502 503 spec->input_mux = preset->input_mux; 504 505 spec->num_adc_nids = preset->num_adc_nids; ··· 1447 } 1448 1449 /* 1450 * Common callbacks 1451 */ 1452 ··· 2174 { .modelname = "lg", .config = ALC880_LG }, 2175 { .pci_subvendor = 0x1854, .pci_subdevice = 0x003b, .config = ALC880_LG }, 2176 2177 #ifdef CONFIG_SND_DEBUG 2178 { .modelname = "test", .config = ALC880_TEST }, 2179 #endif ··· 2366 .input_mux = &alc880_lg_capture_source, 2367 .unsol_event = alc880_lg_unsol_event, 2368 .init_hook = alc880_lg_automute, 2369 }, 2370 #ifdef CONFIG_SND_DEBUG 2371 [ALC880_TEST] = { ··· 2705 2706 spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs; 2707 2708 spec->input_mux = &spec->private_imux; 2709 2710 return 1; ··· 2835 }; 2836 2837 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack, 2838 - * headphone jack and the internal CD lines. 2839 */ 2840 - static struct hda_input_mux alc260_fujitsu_capture_source = { 2841 - .num_items = 3, 2842 - .items = { 2843 - { "Mic/Line", 0x0 }, 2844 - { "CD", 0x4 }, 2845 - { "Headphone", 0x2 }, 2846 }, 2847 }; 2848 2849 - /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configutation to 2850 - * the Fujitsu S702x, but jacks are marked differently. We won't allow 2851 - * retasking the Headphone jack, so it won't be available here. 2852 */ 2853 - static struct hda_input_mux alc260_acer_capture_source = { 2854 - .num_items = 3, 2855 - .items = { 2856 - { "Mic", 0x0 }, 2857 - { "Line", 0x2 }, 2858 - { "CD", 0x4 }, 2859 }, 2860 }; 2861 - 2862 /* 2863 * This is just place-holder, so there's something for alc_build_pcms to look 2864 * at when it calculates the maximum number of channels. ALC260 has no mixer ··· 2945 { } /* end */ 2946 }; 2947 2948 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = { 2949 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT), 2950 HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT), ··· 2964 { } /* end */ 2965 }; 2966 2967 static struct snd_kcontrol_new alc260_acer_mixer[] = { 2968 HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT), 2969 HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT), 2970 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT), 2971 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT), 2972 HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT), ··· 3199 }; 3200 3201 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x 3202 - * laptops. 3203 */ 3204 static struct hda_verb alc260_fujitsu_init_verbs[] = { 3205 /* Disable all GPIOs */ ··· 3347 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00}, 3348 3349 /* Do similar with the second ADC: mute capture input amp and 3350 - * set ADC connection to line (on line1 pin) 3351 */ 3352 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 3353 - {0x05, AC_VERB_SET_CONNECT_SEL, 0x02}, 3354 3355 /* Mute all inputs to mixer widget (even unconnected ones) */ 3356 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ ··· 3375 static hda_nid_t alc260_test_adc_nids[2] = { 3376 0x04, 0x05, 3377 }; 3378 - /* This is a bit messy since the two input muxes in the ALC260 have slight 3379 - * variations in their signal assignments. The ideal way to deal with this 3380 - * is to extend alc_spec.input_mux to allow a different input MUX for each 3381 - * ADC. For the purposes of the test model it's sufficient to just list 3382 - * both options for affected signal indices. The separate input mux 3383 - * functionality only needs to be considered if a model comes along which 3384 - * actually uses signals 0x5, 0x6 and 0x7 for something which makes sense to 3385 - * record. 3386 */ 3387 - static struct hda_input_mux alc260_test_capture_source = { 3388 - .num_items = 8, 3389 - .items = { 3390 - { "MIC1 pin", 0x0 }, 3391 - { "MIC2 pin", 0x1 }, 3392 - { "LINE1 pin", 0x2 }, 3393 - { "LINE2 pin", 0x3 }, 3394 - { "CD pin", 0x4 }, 3395 - { "LINE-OUT pin (cap1), Mixer (cap2)", 0x5 }, 3396 - { "HP-OUT pin (cap1), LINE-OUT pin (cap2)", 0x6 }, 3397 - { "HP-OUT pin (cap2 only)", 0x7 }, 3398 }, 3399 }; 3400 static struct snd_kcontrol_new alc260_test_mixer[] = { ··· 3415 HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT), 3416 HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT), 3417 3418 - /* Modes for retasking pin widgets */ 3419 ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT), 3420 ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT), 3421 ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT), ··· 3787 3788 spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs; 3789 3790 spec->input_mux = &spec->private_imux; 3791 3792 /* check whether NID 0x04 is valid */ ··· 3893 .adc_nids = alc260_dual_adc_nids, 3894 .num_channel_mode = ARRAY_SIZE(alc260_modes), 3895 .channel_mode = alc260_modes, 3896 - .input_mux = &alc260_fujitsu_capture_source, 3897 }, 3898 [ALC260_ACER] = { 3899 .mixers = { alc260_acer_mixer, ··· 3906 .adc_nids = alc260_dual_adc_nids, 3907 .num_channel_mode = ARRAY_SIZE(alc260_modes), 3908 .channel_mode = alc260_modes, 3909 - .input_mux = &alc260_acer_capture_source, 3910 }, 3911 #ifdef CONFIG_SND_DEBUG 3912 [ALC260_TEST] = { ··· 3920 .adc_nids = alc260_test_adc_nids, 3921 .num_channel_mode = ARRAY_SIZE(alc260_modes), 3922 .channel_mode = alc260_modes, 3923 - .input_mux = &alc260_test_capture_source, 3924 }, 3925 #endif 3926 }; ··· 4013 { "CD", 0x4 }, 4014 }, 4015 }; 4016 - 4017 #define alc882_mux_enum_info alc_mux_enum_info 4018 #define alc882_mux_enum_get alc_mux_enum_get 4019 ··· 4914 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 4915 4916 spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs; 4917 spec->input_mux = &spec->private_imux; 4918 4919 return 1; ··· 5591 5592 spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs; 5593 5594 spec->input_mux = &spec->private_imux; 5595 5596 spec->adc_nids = alc861_adc_nids;
··· 52 ALC880_CLEVO, 53 ALC880_TCL_S700, 54 ALC880_LG, 55 + ALC880_LG_LW, 56 #ifdef CONFIG_SND_DEBUG 57 ALC880_TEST, 58 #endif ··· 131 hda_nid_t dig_in_nid; /* digital-in NID; optional */ 132 133 /* capture source */ 134 + unsigned int num_mux_defs; 135 const struct hda_input_mux *input_mux; 136 unsigned int cur_mux[3]; 137 ··· 172 hda_nid_t dig_in_nid; 173 unsigned int num_channel_mode; 174 const struct hda_channel_mode *channel_mode; 175 + unsigned int num_mux_defs; 176 const struct hda_input_mux *input_mux; 177 void (*unsol_event)(struct hda_codec *, unsigned int); 178 void (*init_hook)(struct hda_codec *); ··· 185 { 186 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 187 struct alc_spec *spec = codec->spec; 188 + unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id); 189 + if (mux_idx >= spec->num_mux_defs) 190 + mux_idx = 0; 191 + return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo); 192 } 193 194 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) ··· 203 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 204 struct alc_spec *spec = codec->spec; 205 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 206 + unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; 207 + return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol, 208 spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]); 209 } 210 ··· 245 * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these 246 * are requested. Therefore order this list so that this behaviour will not 247 * cause problems when mixer clients move through the enum sequentially. 248 + * NIDs 0x0f and 0x10 have been observed to have this behaviour as of 249 + * March 2006. 250 */ 251 static char *alc_pin_mode_names[] = { 252 "Mic 50pc bias", "Mic 80pc bias", ··· 255 PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP, 256 }; 257 /* The control can present all 5 options, or it can limit the options based 258 + * in the pin being assumed to be exclusively an input or an output pin. In 259 + * addition, "input" pins may or may not process the mic bias option 260 + * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to 261 + * accept requests for bias as of chip versions up to March 2006) and/or 262 + * wiring in the computer. 263 */ 264 + #define ALC_PIN_DIR_IN 0x00 265 + #define ALC_PIN_DIR_OUT 0x01 266 + #define ALC_PIN_DIR_INOUT 0x02 267 + #define ALC_PIN_DIR_IN_NOMICBIAS 0x03 268 + #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04 269 270 + /* Info about the pin modes supported by the different pin direction modes. 271 * For each direction the minimum and maximum values are given. 272 */ 273 + static signed char alc_pin_mode_dir_info[5][2] = { 274 { 0, 2 }, /* ALC_PIN_DIR_IN */ 275 { 3, 4 }, /* ALC_PIN_DIR_OUT */ 276 { 0, 4 }, /* ALC_PIN_DIR_INOUT */ 277 + { 2, 2 }, /* ALC_PIN_DIR_IN_NOMICBIAS */ 278 + { 2, 4 }, /* ALC_PIN_DIR_INOUT_NOMICBIAS */ 279 }; 280 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0]) 281 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1]) ··· 329 * input modes. 330 * 331 * Dynamically switching the input/output buffers probably 332 + * reduces noise slightly (particularly on input) so we'll 333 + * do it. However, having both input and output buffers 334 + * enabled simultaneously doesn't seem to be problematic if 335 + * this turns out to be necessary in the future. 336 */ 337 if (val <= 2) { 338 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE, ··· 483 spec->multiout.dig_out_nid = preset->dig_out_nid; 484 spec->multiout.hp_nid = preset->hp_nid; 485 486 + spec->num_mux_defs = preset->num_mux_defs; 487 + if (! spec->num_mux_defs) 488 + spec->num_mux_defs = 1; 489 spec->input_mux = preset->input_mux; 490 491 spec->num_adc_nids = preset->num_adc_nids; ··· 1427 } 1428 1429 /* 1430 + * LG LW20 1431 + * 1432 + * Pin assignment: 1433 + * Speaker-out: 0x14 1434 + * Mic-In: 0x18 1435 + * Built-in Mic-In: 0x19 (?) 1436 + * HP-Out: 0x1b 1437 + * SPDIF-Out: 0x1e 1438 + */ 1439 + 1440 + /* seems analog CD is not working */ 1441 + static struct hda_input_mux alc880_lg_lw_capture_source = { 1442 + .num_items = 2, 1443 + .items = { 1444 + { "Mic", 0x0 }, 1445 + { "Internal Mic", 0x1 }, 1446 + }, 1447 + }; 1448 + 1449 + static struct snd_kcontrol_new alc880_lg_lw_mixer[] = { 1450 + HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 1451 + HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT), 1452 + HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 1453 + HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 1454 + HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 1455 + HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 1456 + { } /* end */ 1457 + }; 1458 + 1459 + static struct hda_verb alc880_lg_lw_init_verbs[] = { 1460 + /* set capture source to mic-in */ 1461 + {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 1462 + {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 1463 + {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 1464 + {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)}, 1465 + /* speaker-out */ 1466 + {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1467 + {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1468 + /* HP-out */ 1469 + {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, 1470 + {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 1471 + {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1472 + /* mic-in to input */ 1473 + {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1474 + {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1475 + /* built-in mic */ 1476 + {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1477 + {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1478 + /* jack sense */ 1479 + {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1}, 1480 + { } 1481 + }; 1482 + 1483 + /* toggle speaker-output according to the hp-jack state */ 1484 + static void alc880_lg_lw_automute(struct hda_codec *codec) 1485 + { 1486 + unsigned int present; 1487 + 1488 + present = snd_hda_codec_read(codec, 0x1b, 0, 1489 + AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1490 + snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0, 1491 + 0x80, present ? 0x80 : 0); 1492 + snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0, 1493 + 0x80, present ? 0x80 : 0); 1494 + } 1495 + 1496 + static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res) 1497 + { 1498 + /* Looks like the unsol event is incompatible with the standard 1499 + * definition. 4bit tag is placed at 28 bit! 1500 + */ 1501 + if ((res >> 28) == 0x01) 1502 + alc880_lg_lw_automute(codec); 1503 + } 1504 + 1505 + /* 1506 * Common callbacks 1507 */ 1508 ··· 2078 { .modelname = "lg", .config = ALC880_LG }, 2079 { .pci_subvendor = 0x1854, .pci_subdevice = 0x003b, .config = ALC880_LG }, 2080 2081 + { .modelname = "lg-lw", .config = ALC880_LG_LW }, 2082 + { .pci_subvendor = 0x1854, .pci_subdevice = 0x0018, .config = ALC880_LG_LW }, 2083 + 2084 #ifdef CONFIG_SND_DEBUG 2085 { .modelname = "test", .config = ALC880_TEST }, 2086 #endif ··· 2267 .input_mux = &alc880_lg_capture_source, 2268 .unsol_event = alc880_lg_unsol_event, 2269 .init_hook = alc880_lg_automute, 2270 + }, 2271 + [ALC880_LG_LW] = { 2272 + .mixers = { alc880_lg_lw_mixer }, 2273 + .init_verbs = { alc880_volume_init_verbs, 2274 + alc880_lg_lw_init_verbs }, 2275 + .num_dacs = 1, 2276 + .dac_nids = alc880_dac_nids, 2277 + .dig_out_nid = ALC880_DIGOUT_NID, 2278 + .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes), 2279 + .channel_mode = alc880_2_jack_modes, 2280 + .input_mux = &alc880_lg_lw_capture_source, 2281 + .unsol_event = alc880_lg_lw_unsol_event, 2282 + .init_hook = alc880_lg_lw_automute, 2283 }, 2284 #ifdef CONFIG_SND_DEBUG 2285 [ALC880_TEST] = { ··· 2593 2594 spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs; 2595 2596 + spec->num_mux_defs = 1; 2597 spec->input_mux = &spec->private_imux; 2598 2599 return 1; ··· 2722 }; 2723 2724 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack, 2725 + * headphone jack and the internal CD lines since these are the only pins at 2726 + * which audio can appear. For flexibility, also allow the option of 2727 + * recording the mixer output on the second ADC (ADC0 doesn't have a 2728 + * connection to the mixer output). 2729 */ 2730 + static struct hda_input_mux alc260_fujitsu_capture_sources[2] = { 2731 + { 2732 + .num_items = 3, 2733 + .items = { 2734 + { "Mic/Line", 0x0 }, 2735 + { "CD", 0x4 }, 2736 + { "Headphone", 0x2 }, 2737 + }, 2738 }, 2739 + { 2740 + .num_items = 4, 2741 + .items = { 2742 + { "Mic/Line", 0x0 }, 2743 + { "CD", 0x4 }, 2744 + { "Headphone", 0x2 }, 2745 + { "Mixer", 0x5 }, 2746 + }, 2747 + }, 2748 + 2749 }; 2750 2751 + /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to 2752 + * the Fujitsu S702x, but jacks are marked differently. 2753 */ 2754 + static struct hda_input_mux alc260_acer_capture_sources[2] = { 2755 + { 2756 + .num_items = 4, 2757 + .items = { 2758 + { "Mic", 0x0 }, 2759 + { "Line", 0x2 }, 2760 + { "CD", 0x4 }, 2761 + { "Headphone", 0x5 }, 2762 + }, 2763 + }, 2764 + { 2765 + .num_items = 5, 2766 + .items = { 2767 + { "Mic", 0x0 }, 2768 + { "Line", 0x2 }, 2769 + { "CD", 0x4 }, 2770 + { "Headphone", 0x6 }, 2771 + { "Mixer", 0x5 }, 2772 + }, 2773 }, 2774 }; 2775 /* 2776 * This is just place-holder, so there's something for alc_build_pcms to look 2777 * at when it calculates the maximum number of channels. ALC260 has no mixer ··· 2806 { } /* end */ 2807 }; 2808 2809 + /* Fujitsu S702x series laptops. ALC260 pin usage: Mic/Line jack = 0x12, 2810 + * HP jack = 0x14, CD audio = 0x16, internal speaker = 0x10. 2811 + */ 2812 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = { 2813 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT), 2814 HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT), ··· 2822 { } /* end */ 2823 }; 2824 2825 + /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks. Note that current 2826 + * versions of the ALC260 don't act on requests to enable mic bias from NID 2827 + * 0x0f (used to drive the headphone jack in these laptops). The ALC260 2828 + * datasheet doesn't mention this restriction. At this stage it's not clear 2829 + * whether this behaviour is intentional or is a hardware bug in chip 2830 + * revisions available in early 2006. Therefore for now allow the 2831 + * "Headphone Jack Mode" control to span all choices, but if it turns out 2832 + * that the lack of mic bias for this NID is intentional we could change the 2833 + * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS. 2834 + * 2835 + * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006 2836 + * don't appear to make the mic bias available from the "line" jack, even 2837 + * though the NID used for this jack (0x14) can supply it. The theory is 2838 + * that perhaps Acer have included blocking capacitors between the ALC260 2839 + * and the output jack. If this turns out to be the case for all such 2840 + * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT 2841 + * to ALC_PIN_DIR_INOUT_NOMICBIAS. 2842 + */ 2843 static struct snd_kcontrol_new alc260_acer_mixer[] = { 2844 HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT), 2845 HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT), 2846 + ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT), 2847 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT), 2848 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT), 2849 HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT), ··· 3038 }; 3039 3040 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x 3041 + * laptops. ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD 3042 + * audio = 0x16, internal speaker = 0x10. 3043 */ 3044 static struct hda_verb alc260_fujitsu_init_verbs[] = { 3045 /* Disable all GPIOs */ ··· 3185 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00}, 3186 3187 /* Do similar with the second ADC: mute capture input amp and 3188 + * set ADC connection to mic to match ALSA's default state. 3189 */ 3190 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 3191 + {0x05, AC_VERB_SET_CONNECT_SEL, 0x00}, 3192 3193 /* Mute all inputs to mixer widget (even unconnected ones) */ 3194 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */ ··· 3213 static hda_nid_t alc260_test_adc_nids[2] = { 3214 0x04, 0x05, 3215 }; 3216 + /* For testing the ALC260, each input MUX needs its own definition since 3217 + * the signal assignments are different. This assumes that the first ADC 3218 + * is NID 0x04. 3219 */ 3220 + static struct hda_input_mux alc260_test_capture_sources[2] = { 3221 + { 3222 + .num_items = 7, 3223 + .items = { 3224 + { "MIC1 pin", 0x0 }, 3225 + { "MIC2 pin", 0x1 }, 3226 + { "LINE1 pin", 0x2 }, 3227 + { "LINE2 pin", 0x3 }, 3228 + { "CD pin", 0x4 }, 3229 + { "LINE-OUT pin", 0x5 }, 3230 + { "HP-OUT pin", 0x6 }, 3231 + }, 3232 + }, 3233 + { 3234 + .num_items = 8, 3235 + .items = { 3236 + { "MIC1 pin", 0x0 }, 3237 + { "MIC2 pin", 0x1 }, 3238 + { "LINE1 pin", 0x2 }, 3239 + { "LINE2 pin", 0x3 }, 3240 + { "CD pin", 0x4 }, 3241 + { "Mixer", 0x5 }, 3242 + { "LINE-OUT pin", 0x6 }, 3243 + { "HP-OUT pin", 0x7 }, 3244 + }, 3245 }, 3246 }; 3247 static struct snd_kcontrol_new alc260_test_mixer[] = { ··· 3244 HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT), 3245 HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT), 3246 3247 + /* Modes for retasking pin widgets 3248 + * Note: the ALC260 doesn't seem to act on requests to enable mic 3249 + * bias from NIDs 0x0f and 0x10. The ALC260 datasheet doesn't 3250 + * mention this restriction. At this stage it's not clear whether 3251 + * this behaviour is intentional or is a hardware bug in chip 3252 + * revisions available at least up until early 2006. Therefore for 3253 + * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all 3254 + * choices, but if it turns out that the lack of mic bias for these 3255 + * NIDs is intentional we could change their modes from 3256 + * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS. 3257 + */ 3258 ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT), 3259 ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT), 3260 ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT), ··· 3606 3607 spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs; 3608 3609 + spec->num_mux_defs = 1; 3610 spec->input_mux = &spec->private_imux; 3611 3612 /* check whether NID 0x04 is valid */ ··· 3711 .adc_nids = alc260_dual_adc_nids, 3712 .num_channel_mode = ARRAY_SIZE(alc260_modes), 3713 .channel_mode = alc260_modes, 3714 + .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources), 3715 + .input_mux = alc260_fujitsu_capture_sources, 3716 }, 3717 [ALC260_ACER] = { 3718 .mixers = { alc260_acer_mixer, ··· 3723 .adc_nids = alc260_dual_adc_nids, 3724 .num_channel_mode = ARRAY_SIZE(alc260_modes), 3725 .channel_mode = alc260_modes, 3726 + .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources), 3727 + .input_mux = alc260_acer_capture_sources, 3728 }, 3729 #ifdef CONFIG_SND_DEBUG 3730 [ALC260_TEST] = { ··· 3736 .adc_nids = alc260_test_adc_nids, 3737 .num_channel_mode = ARRAY_SIZE(alc260_modes), 3738 .channel_mode = alc260_modes, 3739 + .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources), 3740 + .input_mux = alc260_test_capture_sources, 3741 }, 3742 #endif 3743 }; ··· 3828 { "CD", 0x4 }, 3829 }, 3830 }; 3831 #define alc882_mux_enum_info alc_mux_enum_info 3832 #define alc882_mux_enum_get alc_mux_enum_get 3833 ··· 4730 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 4731 4732 spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs; 4733 + spec->num_mux_defs = 1; 4734 spec->input_mux = &spec->private_imux; 4735 4736 return 1; ··· 5406 5407 spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs; 5408 5409 + spec->num_mux_defs = 1; 5410 spec->input_mux = &spec->private_imux; 5411 5412 spec->adc_nids = alc861_adc_nids;
+35 -18
sound/pci/hda/patch_sigmatel.c
··· 534 return 0; 535 } 536 537 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type) 538 539 { ··· 587 588 if (val) 589 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN); 590 - else 591 - stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN); 592 - 593 return 1; 594 } 595 ··· 786 return 0; 787 788 wid_caps = get_wcaps(codec, pin); 789 - if (wid_caps & AC_WCAP_UNSOL_CAP) { 790 - /* Enable unsolicited responses on the HP widget */ 791 - snd_hda_codec_write(codec, pin, 0, 792 - AC_VERB_SET_UNSOLICITED_ENABLE, 793 - STAC_UNSOL_ENABLE); 794 spec->hp_detect = 1; 795 - } 796 797 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff; 798 for (i = 0; i < cfg->line_outs; i++) { ··· 910 return 0; 911 912 wid_caps = get_wcaps(codec, pin); 913 - if (wid_caps & AC_WCAP_UNSOL_CAP) { 914 - /* Enable unsolicited responses on the HP widget */ 915 - snd_hda_codec_write(codec, pin, 0, 916 - AC_VERB_SET_UNSOLICITED_ENABLE, 917 - STAC_UNSOL_ENABLE); 918 spec->hp_detect = 1; 919 - } 920 921 return 0; 922 } ··· 953 954 /* set up pins */ 955 if (spec->hp_detect) { 956 /* fake event to set up pins */ 957 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); 958 } else { ··· 964 stac92xx_auto_init_hp_out(codec); 965 } 966 for (i = 0; i < AUTO_PIN_LAST; i++) { 967 - if (cfg->input_pins[i]) 968 - stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], 969 - AC_PINCTL_IN_EN); 970 } 971 if (cfg->dig_out_pin) 972 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
··· 534 return 0; 535 } 536 537 + static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid) 538 + { 539 + unsigned int pincap = snd_hda_param_read(codec, nid, 540 + AC_PAR_PIN_CAP); 541 + pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; 542 + if (pincap & AC_PINCAP_VREF_100) 543 + return AC_PINCTL_VREF_100; 544 + if (pincap & AC_PINCAP_VREF_80) 545 + return AC_PINCTL_VREF_80; 546 + if (pincap & AC_PINCAP_VREF_50) 547 + return AC_PINCTL_VREF_50; 548 + if (pincap & AC_PINCAP_VREF_GRD) 549 + return AC_PINCTL_VREF_GRD; 550 + return 0; 551 + } 552 + 553 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type) 554 555 { ··· 571 572 if (val) 573 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN); 574 + else { 575 + unsigned int pinctl = AC_PINCTL_IN_EN; 576 + if (io_idx) /* set VREF for mic */ 577 + pinctl |= stac92xx_get_vref(codec, nid); 578 + stac92xx_auto_set_pinctl(codec, nid, pinctl); 579 + } 580 return 1; 581 } 582 ··· 767 return 0; 768 769 wid_caps = get_wcaps(codec, pin); 770 + if (wid_caps & AC_WCAP_UNSOL_CAP) 771 spec->hp_detect = 1; 772 773 nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff; 774 for (i = 0; i < cfg->line_outs; i++) { ··· 896 return 0; 897 898 wid_caps = get_wcaps(codec, pin); 899 + if (wid_caps & AC_WCAP_UNSOL_CAP) 900 spec->hp_detect = 1; 901 902 return 0; 903 } ··· 944 945 /* set up pins */ 946 if (spec->hp_detect) { 947 + /* Enable unsolicited responses on the HP widget */ 948 + snd_hda_codec_write(codec, cfg->hp_pin, 0, 949 + AC_VERB_SET_UNSOLICITED_ENABLE, 950 + STAC_UNSOL_ENABLE); 951 /* fake event to set up pins */ 952 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); 953 } else { ··· 951 stac92xx_auto_init_hp_out(codec); 952 } 953 for (i = 0; i < AUTO_PIN_LAST; i++) { 954 + hda_nid_t nid = cfg->input_pins[i]; 955 + if (nid) { 956 + unsigned int pinctl = AC_PINCTL_IN_EN; 957 + if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) 958 + pinctl |= stac92xx_get_vref(codec, nid); 959 + stac92xx_auto_set_pinctl(codec, nid, pinctl); 960 + } 961 } 962 if (cfg->dig_out_pin) 963 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
+160 -3
sound/pci/ice1712/aureon.c
··· 87 #define CS8415_C_BUFFER 0x20 88 #define CS8415_ID 0x7F 89 90 - static void aureon_ac97_write(struct snd_ice1712 *ice, unsigned short reg, unsigned short val) { 91 unsigned int tmp; 92 93 /* Send address to XILINX chip */ ··· 290 /* 291 * Initialize STAC9744 chip 292 */ 293 - static int aureon_ac97_init (struct snd_ice1712 *ice) { 294 int i; 295 static unsigned short ac97_defaults[] = { 296 0x00, 0x9640, ··· 1743 .get = aureon_ac97_vol_get, 1744 .put = aureon_ac97_vol_put, 1745 .private_value = AC97_VIDEO|AUREON_AC97_STEREO 1746 - } 1747 }; 1748 1749 ··· 2009 } 2010 2011 snd_ice1712_restore_gpio_status(ice); 2012 2013 ice->spec.aureon.master[0] = WM_VOL_MUTE; 2014 ice->spec.aureon.master[1] = WM_VOL_MUTE;
··· 87 #define CS8415_C_BUFFER 0x20 88 #define CS8415_ID 0x7F 89 90 + /* PCA9554 registers */ 91 + #define PCA9554_DEV 0x40 /* I2C device address */ 92 + #define PCA9554_IN 0x00 /* input port */ 93 + #define PCA9554_OUT 0x01 /* output port */ 94 + #define PCA9554_INVERT 0x02 /* input invert */ 95 + #define PCA9554_DIR 0x03 /* port directions */ 96 + 97 + /* 98 + * Aureon Universe additional controls using PCA9554 99 + */ 100 + 101 + /* 102 + * Send data to pca9554 103 + */ 104 + static void aureon_pca9554_write(struct snd_ice1712 *ice, unsigned char reg, 105 + unsigned char data) 106 + { 107 + unsigned int tmp; 108 + int i, j; 109 + unsigned char dev = PCA9554_DEV; /* ID 0100000, write */ 110 + unsigned char val = 0; 111 + 112 + tmp = snd_ice1712_gpio_read(ice); 113 + 114 + snd_ice1712_gpio_set_mask(ice, ~(AUREON_SPI_MOSI|AUREON_SPI_CLK| 115 + AUREON_WM_RW|AUREON_WM_CS| 116 + AUREON_CS8415_CS)); 117 + tmp |= AUREON_WM_RW; 118 + tmp |= AUREON_CS8415_CS | AUREON_WM_CS; /* disable SPI devices */ 119 + 120 + tmp &= ~AUREON_SPI_MOSI; 121 + tmp &= ~AUREON_SPI_CLK; 122 + snd_ice1712_gpio_write(ice, tmp); 123 + udelay(50); 124 + 125 + /* 126 + * send i2c stop condition and start condition 127 + * to obtain sane state 128 + */ 129 + tmp |= AUREON_SPI_CLK; 130 + snd_ice1712_gpio_write(ice, tmp); 131 + udelay(50); 132 + tmp |= AUREON_SPI_MOSI; 133 + snd_ice1712_gpio_write(ice, tmp); 134 + udelay(100); 135 + tmp &= ~AUREON_SPI_MOSI; 136 + snd_ice1712_gpio_write(ice, tmp); 137 + udelay(50); 138 + tmp &= ~AUREON_SPI_CLK; 139 + snd_ice1712_gpio_write(ice, tmp); 140 + udelay(100); 141 + /* 142 + * send device address, command and value, 143 + * skipping ack cycles inbetween 144 + */ 145 + for (j = 0; j < 3; j++) { 146 + switch(j) { 147 + case 0: val = dev; break; 148 + case 1: val = reg; break; 149 + case 2: val = data; break; 150 + } 151 + for (i = 7; i >= 0; i--) { 152 + tmp &= ~AUREON_SPI_CLK; 153 + snd_ice1712_gpio_write(ice, tmp); 154 + udelay(40); 155 + if (val & (1 << i)) 156 + tmp |= AUREON_SPI_MOSI; 157 + else 158 + tmp &= ~AUREON_SPI_MOSI; 159 + snd_ice1712_gpio_write(ice, tmp); 160 + udelay(40); 161 + tmp |= AUREON_SPI_CLK; 162 + snd_ice1712_gpio_write(ice, tmp); 163 + udelay(40); 164 + } 165 + tmp &= ~AUREON_SPI_CLK; 166 + snd_ice1712_gpio_write(ice, tmp); 167 + udelay(40); 168 + tmp |= AUREON_SPI_CLK; 169 + snd_ice1712_gpio_write(ice, tmp); 170 + udelay(40); 171 + tmp &= ~AUREON_SPI_CLK; 172 + snd_ice1712_gpio_write(ice, tmp); 173 + udelay(40); 174 + } 175 + tmp &= ~AUREON_SPI_CLK; 176 + snd_ice1712_gpio_write(ice, tmp); 177 + udelay(40); 178 + tmp &= ~AUREON_SPI_MOSI; 179 + snd_ice1712_gpio_write(ice, tmp); 180 + udelay(40); 181 + tmp |= AUREON_SPI_CLK; 182 + snd_ice1712_gpio_write(ice, tmp); 183 + udelay(50); 184 + tmp |= AUREON_SPI_MOSI; 185 + snd_ice1712_gpio_write(ice, tmp); 186 + udelay(100); 187 + } 188 + 189 + static int aureon_universe_inmux_info(struct snd_kcontrol *kcontrol, 190 + struct snd_ctl_elem_info *uinfo) 191 + { 192 + char *texts[3] = {"Internal Aux", "Wavetable", "Rear Line-In"}; 193 + 194 + uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 195 + uinfo->count = 1; 196 + uinfo->value.enumerated.items = 3; 197 + if(uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 198 + uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 199 + strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 200 + return 0; 201 + } 202 + 203 + static int aureon_universe_inmux_get(struct snd_kcontrol *kcontrol, 204 + struct snd_ctl_elem_value *ucontrol) 205 + { 206 + struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 207 + ucontrol->value.integer.value[0] = ice->spec.aureon.pca9554_out; 208 + return 0; 209 + } 210 + 211 + static int aureon_universe_inmux_put(struct snd_kcontrol *kcontrol, 212 + struct snd_ctl_elem_value *ucontrol) 213 + { 214 + struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 215 + unsigned char oval, nval; 216 + int change; 217 + 218 + snd_ice1712_save_gpio_status(ice); 219 + 220 + oval = ice->spec.aureon.pca9554_out; 221 + nval = ucontrol->value.integer.value[0]; 222 + if ((change = (oval != nval))) { 223 + aureon_pca9554_write(ice, PCA9554_OUT, nval); 224 + ice->spec.aureon.pca9554_out = nval; 225 + } 226 + snd_ice1712_restore_gpio_status(ice); 227 + 228 + return change; 229 + } 230 + 231 + 232 + static void aureon_ac97_write(struct snd_ice1712 *ice, unsigned short reg, 233 + unsigned short val) 234 + { 235 unsigned int tmp; 236 237 /* Send address to XILINX chip */ ··· 146 /* 147 * Initialize STAC9744 chip 148 */ 149 + static int aureon_ac97_init (struct snd_ice1712 *ice) 150 + { 151 int i; 152 static unsigned short ac97_defaults[] = { 153 0x00, 0x9640, ··· 1598 .get = aureon_ac97_vol_get, 1599 .put = aureon_ac97_vol_put, 1600 .private_value = AC97_VIDEO|AUREON_AC97_STEREO 1601 + }, 1602 + { 1603 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1604 + .name = "Aux Source", 1605 + .info = aureon_universe_inmux_info, 1606 + .get = aureon_universe_inmux_get, 1607 + .put = aureon_universe_inmux_put 1608 + } 1609 + 1610 }; 1611 1612 ··· 1856 } 1857 1858 snd_ice1712_restore_gpio_status(ice); 1859 + 1860 + /* initialize PCA9554 pin directions & set default input*/ 1861 + aureon_pca9554_write(ice, PCA9554_DIR, 0x00); 1862 + aureon_pca9554_write(ice, PCA9554_OUT, 0x00); /* internal AUX */ 1863 1864 ice->spec.aureon.master[0] = WM_VOL_MUTE; 1865 ice->spec.aureon.master[1] = WM_VOL_MUTE;
+1 -1
sound/pci/ice1712/ice1712.c
··· 2402 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DMX6FIRE && !ice->dxr_enable) { 2403 /* Limit active ADCs and DACs to 6; */ 2404 /* Note: DXR extension not supported */ 2405 - pci_write_config_byte(ice->pci, 0x60, 0x0a); 2406 } else { 2407 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]); 2408 }
··· 2402 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DMX6FIRE && !ice->dxr_enable) { 2403 /* Limit active ADCs and DACs to 6; */ 2404 /* Note: DXR extension not supported */ 2405 + pci_write_config_byte(ice->pci, 0x60, 0x2a); 2406 } else { 2407 pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]); 2408 }
+1
sound/pci/ice1712/ice1712.h
··· 373 unsigned int cs8415_mux; 374 unsigned short master[2]; 375 unsigned short vol[8]; 376 } aureon; 377 /* AC97 register cache for Phase28 */ 378 struct phase28_spec {
··· 373 unsigned int cs8415_mux; 374 unsigned short master[2]; 375 unsigned short vol[8]; 376 + unsigned char pca9554_out; 377 } aureon; 378 /* AC97 register cache for Phase28 */ 379 struct phase28_spec {
+37 -20
sound/pci/maestro3.c
··· 831 struct snd_pcm *pcm; 832 833 struct pci_dev *pci; 834 - struct m3_quirk *quirk; 835 - struct m3_hv_quirk *hv_quirk; 836 837 int dacs_active; 838 int timer_users; ··· 892 893 MODULE_DEVICE_TABLE(pci, snd_m3_ids); 894 895 - static struct m3_quirk m3_quirk_list[] = { 896 /* panasonic CF-28 "toughbook" */ 897 { 898 .name = "Panasonic CF-28", ··· 950 }; 951 952 /* These values came from the Windows driver. */ 953 - static struct m3_hv_quirk m3_hv_quirk_list[] = { 954 /* Allegro chips */ 955 { 0x125D, 0x1988, 0x0E11, 0x002E, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 }, 956 { 0x125D, 0x1988, 0x0E11, 0x0094, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 }, ··· 1361 } 1362 1363 1364 - static struct play_vals { 1365 u16 addr, val; 1366 } pv[] = { 1367 {CDATA_LEFT_VOLUME, ARB_VOLUME}, ··· 1428 /* 1429 * Native record driver 1430 */ 1431 - static struct rec_vals { 1432 u16 addr, val; 1433 } rv[] = { 1434 {CDATA_LEFT_VOLUME, ARB_VOLUME}, ··· 1598 if (! s->running) 1599 return; 1600 1601 - hwptr = snd_m3_get_pointer(chip, s, subs) % s->dma_size; 1602 - diff = (s->dma_size + hwptr - s->hwptr) % s->dma_size; 1603 s->hwptr = hwptr; 1604 s->count += diff; 1605 if (s->count >= (signed)s->period_size) { 1606 - s->count %= s->period_size; 1607 spin_unlock(&chip->reg_lock); 1608 snd_pcm_period_elapsed(subs); 1609 spin_lock(&chip->reg_lock); ··· 1956 do { 1957 if (! (snd_m3_inb(chip, 0x30) & 1)) 1958 return 0; 1959 } while (i-- > 0); 1960 1961 snd_printk(KERN_ERR "ac97 serial bus busy\n"); ··· 1968 { 1969 struct snd_m3 *chip = ac97->private_data; 1970 unsigned long flags; 1971 - unsigned short data; 1972 1973 if (snd_m3_ac97_wait(chip)) 1974 - return 0xffff; 1975 spin_lock_irqsave(&chip->ac97_lock, flags); 1976 snd_m3_outb(chip, 0x80 | (reg & 0x7f), CODEC_COMMAND); 1977 if (snd_m3_ac97_wait(chip)) 1978 - return 0xffff; 1979 data = snd_m3_inw(chip, CODEC_DATA); 1980 spin_unlock_irqrestore(&chip->ac97_lock, flags); 1981 return data; 1982 } 1983 ··· 2138 * DSP Code images 2139 */ 2140 2141 - static u16 assp_kernel_image[] __devinitdata = { 2142 0x7980, 0x0030, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x00FB, 0x7980, 0x00DD, 0x7980, 0x03B4, 2143 0x7980, 0x0332, 0x7980, 0x0287, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4, 2144 0x7980, 0x031A, 0x7980, 0x03B4, 0x7980, 0x022F, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4, ··· 2225 * Mini sample rate converter code image 2226 * that is to be loaded at 0x400 on the DSP. 2227 */ 2228 - static u16 assp_minisrc_image[] __devinitdata = { 2229 2230 0xBF80, 0x101E, 0x906E, 0x006E, 0x8B88, 0x6980, 0xEF88, 0x906F, 0x0D6F, 0x6900, 0xEB08, 0x0412, 2231 0xBC20, 0x696E, 0xB801, 0x906E, 0x7980, 0x0403, 0xB90E, 0x8807, 0xBE43, 0xBF01, 0xBE47, 0xBE41, ··· 2268 */ 2269 2270 #define MINISRC_LPF_LEN 10 2271 - static u16 minisrc_lpf[MINISRC_LPF_LEN] __devinitdata = { 2272 0X0743, 0X1104, 0X0A4C, 0XF88D, 0X242C, 2273 0X1023, 0X1AA9, 0X0B60, 0XEFDD, 0X186F 2274 }; ··· 2375 */ 2376 2377 /* 2378 - * align instance address to 256 bytes so that it's 2379 * shifted list address is aligned. 2380 * list address = (mem address >> 1) >> 7; 2381 */ ··· 2664 { 2665 struct snd_m3 *chip; 2666 int i, err; 2667 - struct m3_quirk *quirk; 2668 - struct m3_hv_quirk *hv_quirk; 2669 static struct snd_device_ops ops = { 2670 .dev_free = snd_m3_dev_free, 2671 }; ··· 2860 } 2861 2862 #if 0 /* TODO: not supported yet */ 2863 - /* TODO enable midi irq and i/o */ 2864 err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401, 2865 chip->iobase + MPU401_DATA_PORT, 1, 2866 chip->irq, 0, &chip->rmidi); 2867 if (err < 0) 2868 - printk(KERN_WARNING "maestro3: no midi support.\n"); 2869 #endif 2870 2871 pci_set_drvdata(pci, card);
··· 831 struct snd_pcm *pcm; 832 833 struct pci_dev *pci; 834 + const struct m3_quirk *quirk; 835 + const struct m3_hv_quirk *hv_quirk; 836 837 int dacs_active; 838 int timer_users; ··· 892 893 MODULE_DEVICE_TABLE(pci, snd_m3_ids); 894 895 + static const struct m3_quirk m3_quirk_list[] = { 896 /* panasonic CF-28 "toughbook" */ 897 { 898 .name = "Panasonic CF-28", ··· 950 }; 951 952 /* These values came from the Windows driver. */ 953 + static const struct m3_hv_quirk m3_hv_quirk_list[] = { 954 /* Allegro chips */ 955 { 0x125D, 0x1988, 0x0E11, 0x002E, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 }, 956 { 0x125D, 0x1988, 0x0E11, 0x0094, HV_CTRL_ENABLE | HV_BUTTON_FROM_GD, 0 }, ··· 1361 } 1362 1363 1364 + static const struct play_vals { 1365 u16 addr, val; 1366 } pv[] = { 1367 {CDATA_LEFT_VOLUME, ARB_VOLUME}, ··· 1428 /* 1429 * Native record driver 1430 */ 1431 + static const struct rec_vals { 1432 u16 addr, val; 1433 } rv[] = { 1434 {CDATA_LEFT_VOLUME, ARB_VOLUME}, ··· 1598 if (! s->running) 1599 return; 1600 1601 + hwptr = snd_m3_get_pointer(chip, s, subs); 1602 + 1603 + /* try to avoid expensive modulo divisions */ 1604 + if (hwptr >= s->dma_size) 1605 + hwptr %= s->dma_size; 1606 + 1607 + diff = s->dma_size + hwptr - s->hwptr; 1608 + if (diff >= s->dma_size) 1609 + diff %= s->dma_size; 1610 + 1611 s->hwptr = hwptr; 1612 s->count += diff; 1613 + 1614 if (s->count >= (signed)s->period_size) { 1615 + 1616 + if (s->count < 2 * (signed)s->period_size) 1617 + s->count -= (signed)s->period_size; 1618 + else 1619 + s->count %= s->period_size; 1620 + 1621 spin_unlock(&chip->reg_lock); 1622 snd_pcm_period_elapsed(subs); 1623 spin_lock(&chip->reg_lock); ··· 1942 do { 1943 if (! (snd_m3_inb(chip, 0x30) & 1)) 1944 return 0; 1945 + cpu_relax(); 1946 } while (i-- > 0); 1947 1948 snd_printk(KERN_ERR "ac97 serial bus busy\n"); ··· 1953 { 1954 struct snd_m3 *chip = ac97->private_data; 1955 unsigned long flags; 1956 + unsigned short data = 0xffff; 1957 1958 if (snd_m3_ac97_wait(chip)) 1959 + goto fail; 1960 spin_lock_irqsave(&chip->ac97_lock, flags); 1961 snd_m3_outb(chip, 0x80 | (reg & 0x7f), CODEC_COMMAND); 1962 if (snd_m3_ac97_wait(chip)) 1963 + goto fail_unlock; 1964 data = snd_m3_inw(chip, CODEC_DATA); 1965 + fail_unlock: 1966 spin_unlock_irqrestore(&chip->ac97_lock, flags); 1967 + fail: 1968 return data; 1969 } 1970 ··· 2121 * DSP Code images 2122 */ 2123 2124 + static const u16 assp_kernel_image[] __devinitdata = { 2125 0x7980, 0x0030, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x00FB, 0x7980, 0x00DD, 0x7980, 0x03B4, 2126 0x7980, 0x0332, 0x7980, 0x0287, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4, 2127 0x7980, 0x031A, 0x7980, 0x03B4, 0x7980, 0x022F, 0x7980, 0x03B4, 0x7980, 0x03B4, 0x7980, 0x03B4, ··· 2208 * Mini sample rate converter code image 2209 * that is to be loaded at 0x400 on the DSP. 2210 */ 2211 + static const u16 assp_minisrc_image[] __devinitdata = { 2212 2213 0xBF80, 0x101E, 0x906E, 0x006E, 0x8B88, 0x6980, 0xEF88, 0x906F, 0x0D6F, 0x6900, 0xEB08, 0x0412, 2214 0xBC20, 0x696E, 0xB801, 0x906E, 0x7980, 0x0403, 0xB90E, 0x8807, 0xBE43, 0xBF01, 0xBE47, 0xBE41, ··· 2251 */ 2252 2253 #define MINISRC_LPF_LEN 10 2254 + static const u16 minisrc_lpf[MINISRC_LPF_LEN] __devinitdata = { 2255 0X0743, 0X1104, 0X0A4C, 0XF88D, 0X242C, 2256 0X1023, 0X1AA9, 0X0B60, 0XEFDD, 0X186F 2257 }; ··· 2358 */ 2359 2360 /* 2361 + * align instance address to 256 bytes so that its 2362 * shifted list address is aligned. 2363 * list address = (mem address >> 1) >> 7; 2364 */ ··· 2647 { 2648 struct snd_m3 *chip; 2649 int i, err; 2650 + const struct m3_quirk *quirk; 2651 + const struct m3_hv_quirk *hv_quirk; 2652 static struct snd_device_ops ops = { 2653 .dev_free = snd_m3_dev_free, 2654 }; ··· 2843 } 2844 2845 #if 0 /* TODO: not supported yet */ 2846 + /* TODO enable MIDI IRQ and I/O */ 2847 err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401, 2848 chip->iobase + MPU401_DATA_PORT, 1, 2849 chip->irq, 0, &chip->rmidi); 2850 if (err < 0) 2851 + printk(KERN_WARNING "maestro3: no MIDI support.\n"); 2852 #endif 2853 2854 pci_set_drvdata(pci, card);
+3 -6
sound/pci/pcxhr/pcxhr_core.c
··· 274 275 /* test first xilinx */ 276 chipsc = PCXHR_INPL(mgr, PCXHR_PLX_CHIPSC); 277 - if (!second) { 278 - if (chipsc & PCXHR_CHIPSC_GPI_USERI) { 279 - snd_printdd("no need to load first xilinx\n"); 280 - return 0; /* first xilinx is already present and cannot be reset */ 281 - } 282 - } else { 283 if ((chipsc & PCXHR_CHIPSC_GPI_USERI) == 0) { 284 snd_printk(KERN_ERR "error loading first xilinx\n"); 285 return -EINVAL;
··· 274 275 /* test first xilinx */ 276 chipsc = PCXHR_INPL(mgr, PCXHR_PLX_CHIPSC); 277 + /* REV01 cards do not support the PCXHR_CHIPSC_GPI_USERI bit anymore */ 278 + /* this bit will always be 1; no possibility to test presence of first xilinx */ 279 + if(second) { 280 if ((chipsc & PCXHR_CHIPSC_GPI_USERI) == 0) { 281 snd_printk(KERN_ERR "error loading first xilinx\n"); 282 return -EINVAL;
+3
sound/pci/riptide/Makefile
···
··· 1 + snd-riptide-objs := riptide.o 2 + 3 + obj-$(CONFIG_SND_RIPTIDE) += snd-riptide.o
+2223
sound/pci/riptide/riptide.c
···
··· 1 + /* 2 + * Driver for the Conexant Riptide Soundchip 3 + * 4 + * Copyright (c) 2004 Peter Gruber <nokos@gmx.net> 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 + History: 23 + - 02/15/2004 first release 24 + 25 + This Driver is based on the OSS Driver version from Linuxant (riptide-0.6lnxtbeta03111100) 26 + credits from the original files: 27 + 28 + MODULE NAME: cnxt_rt.h 29 + AUTHOR: K. Lazarev (Transcribed by KNL) 30 + HISTORY: Major Revision Date By 31 + ----------------------------- -------- ----- 32 + Created 02/1/2000 KNL 33 + 34 + MODULE NAME: int_mdl.c 35 + AUTHOR: Konstantin Lazarev (Transcribed by KNL) 36 + HISTORY: Major Revision Date By 37 + ----------------------------- -------- ----- 38 + Created 10/01/99 KNL 39 + 40 + MODULE NAME: riptide.h 41 + AUTHOR: O. Druzhinin (Transcribed by OLD) 42 + HISTORY: Major Revision Date By 43 + ----------------------------- -------- ----- 44 + Created 10/16/97 OLD 45 + 46 + MODULE NAME: Rp_Cmdif.cpp 47 + AUTHOR: O. Druzhinin (Transcribed by OLD) 48 + K. Lazarev (Transcribed by KNL) 49 + HISTORY: Major Revision Date By 50 + ----------------------------- -------- ----- 51 + Adopted from NT4 driver 6/22/99 OLD 52 + Ported to Linux 9/01/99 KNL 53 + 54 + MODULE NAME: rt_hw.c 55 + AUTHOR: O. Druzhinin (Transcribed by OLD) 56 + C. Lazarev (Transcribed by CNL) 57 + HISTORY: Major Revision Date By 58 + ----------------------------- -------- ----- 59 + Created 11/18/97 OLD 60 + Hardware functions for RipTide 11/24/97 CNL 61 + (ES1) are coded 62 + Hardware functions for RipTide 12/24/97 CNL 63 + (A0) are coded 64 + Hardware functions for RipTide 03/20/98 CNL 65 + (A1) are coded 66 + Boot loader is included 05/07/98 CNL 67 + Redesigned for WDM 07/27/98 CNL 68 + Redesigned for Linux 09/01/99 CNL 69 + 70 + MODULE NAME: rt_hw.h 71 + AUTHOR: C. Lazarev (Transcribed by CNL) 72 + HISTORY: Major Revision Date By 73 + ----------------------------- -------- ----- 74 + Created 11/18/97 CNL 75 + 76 + MODULE NAME: rt_mdl.c 77 + AUTHOR: Konstantin Lazarev (Transcribed by KNL) 78 + HISTORY: Major Revision Date By 79 + ----------------------------- -------- ----- 80 + Created 10/01/99 KNL 81 + 82 + MODULE NAME: mixer.h 83 + AUTHOR: K. Kenney 84 + HISTORY: Major Revision Date By 85 + ----------------------------- -------- ----- 86 + Created from MS W95 Sample 11/28/95 KRS 87 + RipTide 10/15/97 KRS 88 + Adopted for Windows NT driver 01/20/98 CNL 89 + */ 90 + 91 + #include <sound/driver.h> 92 + #include <linux/delay.h> 93 + #include <linux/init.h> 94 + #include <linux/interrupt.h> 95 + #include <linux/pci.h> 96 + #include <linux/slab.h> 97 + #include <linux/wait.h> 98 + #include <linux/gameport.h> 99 + #include <linux/device.h> 100 + #include <linux/firmware.h> 101 + #include <asm/io.h> 102 + #include <sound/core.h> 103 + #include <sound/info.h> 104 + #include <sound/control.h> 105 + #include <sound/pcm.h> 106 + #include <sound/pcm_params.h> 107 + #include <sound/ac97_codec.h> 108 + #include <sound/mpu401.h> 109 + #include <sound/opl3.h> 110 + #include <sound/initval.h> 111 + 112 + #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) 113 + #define SUPPORT_JOYSTICK 1 114 + #endif 115 + 116 + MODULE_AUTHOR("Peter Gruber <nokos@gmx.net>"); 117 + MODULE_DESCRIPTION("riptide"); 118 + MODULE_LICENSE("GPL"); 119 + MODULE_SUPPORTED_DEVICE("{{Conexant,Riptide}}"); 120 + 121 + static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 122 + static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 123 + static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; 124 + 125 + #ifdef SUPPORT_JOYSTICK 126 + static int joystick_port[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1)] = 0x200 }; 127 + #endif 128 + static int mpu_port[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1)] = 0x330 }; 129 + static int opl3_port[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1)] = 0x388 }; 130 + 131 + module_param_array(index, int, NULL, 0444); 132 + MODULE_PARM_DESC(index, "Index value for Riptide soundcard."); 133 + module_param_array(id, charp, NULL, 0444); 134 + MODULE_PARM_DESC(id, "ID string for Riptide soundcard."); 135 + module_param_array(enable, bool, NULL, 0444); 136 + MODULE_PARM_DESC(enable, "Enable Riptide soundcard."); 137 + #ifdef SUPPORT_JOYSTICK 138 + module_param_array(joystick_port, int, NULL, 0444); 139 + MODULE_PARM_DESC(joystick_port, "Joystick port # for Riptide soundcard."); 140 + #endif 141 + module_param_array(mpu_port, int, NULL, 0444); 142 + MODULE_PARM_DESC(mpu_port, "MPU401 port # for Riptide driver."); 143 + module_param_array(opl3_port, int, NULL, 0444); 144 + MODULE_PARM_DESC(opl3_port, "OPL3 port # for Riptide driver."); 145 + 146 + /* 147 + */ 148 + 149 + #define MPU401_HW_RIPTIDE MPU401_HW_MPU401 150 + #define OPL3_HW_RIPTIDE OPL3_HW_OPL3 151 + 152 + #define PCI_EXT_CapId 0x40 153 + #define PCI_EXT_NextCapPrt 0x41 154 + #define PCI_EXT_PWMC 0x42 155 + #define PCI_EXT_PWSCR 0x44 156 + #define PCI_EXT_Data00 0x46 157 + #define PCI_EXT_PMSCR_BSE 0x47 158 + #define PCI_EXT_SB_Base 0x48 159 + #define PCI_EXT_FM_Base 0x4a 160 + #define PCI_EXT_MPU_Base 0x4C 161 + #define PCI_EXT_Game_Base 0x4E 162 + #define PCI_EXT_Legacy_Mask 0x50 163 + #define PCI_EXT_AsicRev 0x52 164 + #define PCI_EXT_Reserved3 0x53 165 + 166 + #define LEGACY_ENABLE_ALL 0x8000 /* legacy device options */ 167 + #define LEGACY_ENABLE_SB 0x4000 168 + #define LEGACY_ENABLE_FM 0x2000 169 + #define LEGACY_ENABLE_MPU_INT 0x1000 170 + #define LEGACY_ENABLE_MPU 0x0800 171 + #define LEGACY_ENABLE_GAMEPORT 0x0400 172 + 173 + #define MAX_WRITE_RETRY 10 /* cmd interface limits */ 174 + #define MAX_ERROR_COUNT 10 175 + #define CMDIF_TIMEOUT 500000 176 + #define RESET_TRIES 5 177 + 178 + #define READ_PORT_ULONG(p) inl((unsigned long)&(p)) 179 + #define WRITE_PORT_ULONG(p,x) outl(x,(unsigned long)&(p)) 180 + 181 + #define READ_AUDIO_CONTROL(p) READ_PORT_ULONG(p->audio_control) 182 + #define WRITE_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,x) 183 + #define UMASK_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,READ_PORT_ULONG(p->audio_control)|x) 184 + #define MASK_AUDIO_CONTROL(p,x) WRITE_PORT_ULONG(p->audio_control,READ_PORT_ULONG(p->audio_control)&x) 185 + #define READ_AUDIO_STATUS(p) READ_PORT_ULONG(p->audio_status) 186 + 187 + #define SET_GRESET(p) UMASK_AUDIO_CONTROL(p,0x0001) /* global reset switch */ 188 + #define UNSET_GRESET(p) MASK_AUDIO_CONTROL(p,~0x0001) 189 + #define SET_AIE(p) UMASK_AUDIO_CONTROL(p,0x0004) /* interrupt enable */ 190 + #define UNSET_AIE(p) MASK_AUDIO_CONTROL(p,~0x0004) 191 + #define SET_AIACK(p) UMASK_AUDIO_CONTROL(p,0x0008) /* interrupt acknowledge */ 192 + #define UNSET_AIACKT(p) MASKAUDIO_CONTROL(p,~0x0008) 193 + #define SET_ECMDAE(p) UMASK_AUDIO_CONTROL(p,0x0010) 194 + #define UNSET_ECMDAE(p) MASK_AUDIO_CONTROL(p,~0x0010) 195 + #define SET_ECMDBE(p) UMASK_AUDIO_CONTROL(p,0x0020) 196 + #define UNSET_ECMDBE(p) MASK_AUDIO_CONTROL(p,~0x0020) 197 + #define SET_EDATAF(p) UMASK_AUDIO_CONTROL(p,0x0040) 198 + #define UNSET_EDATAF(p) MASK_AUDIO_CONTROL(p,~0x0040) 199 + #define SET_EDATBF(p) UMASK_AUDIO_CONTROL(p,0x0080) 200 + #define UNSET_EDATBF(p) MASK_AUDIO_CONTROL(p,~0x0080) 201 + #define SET_ESBIRQON(p) UMASK_AUDIO_CONTROL(p,0x0100) 202 + #define UNSET_ESBIRQON(p) MASK_AUDIO_CONTROL(p,~0x0100) 203 + #define SET_EMPUIRQ(p) UMASK_AUDIO_CONTROL(p,0x0200) 204 + #define UNSET_EMPUIRQ(p) MASK_AUDIO_CONTROL(p,~0x0200) 205 + #define IS_CMDE(a) (READ_PORT_ULONG(a->stat)&0x1) /* cmd empty */ 206 + #define IS_DATF(a) (READ_PORT_ULONG(a->stat)&0x2) /* data filled */ 207 + #define IS_READY(p) (READ_AUDIO_STATUS(p)&0x0001) 208 + #define IS_DLREADY(p) (READ_AUDIO_STATUS(p)&0x0002) 209 + #define IS_DLERR(p) (READ_AUDIO_STATUS(p)&0x0004) 210 + #define IS_GERR(p) (READ_AUDIO_STATUS(p)&0x0008) /* error ! */ 211 + #define IS_CMDAEIRQ(p) (READ_AUDIO_STATUS(p)&0x0010) 212 + #define IS_CMDBEIRQ(p) (READ_AUDIO_STATUS(p)&0x0020) 213 + #define IS_DATAFIRQ(p) (READ_AUDIO_STATUS(p)&0x0040) 214 + #define IS_DATBFIRQ(p) (READ_AUDIO_STATUS(p)&0x0080) 215 + #define IS_EOBIRQ(p) (READ_AUDIO_STATUS(p)&0x0100) /* interrupt status */ 216 + #define IS_EOSIRQ(p) (READ_AUDIO_STATUS(p)&0x0200) 217 + #define IS_EOCIRQ(p) (READ_AUDIO_STATUS(p)&0x0400) 218 + #define IS_UNSLIRQ(p) (READ_AUDIO_STATUS(p)&0x0800) 219 + #define IS_SBIRQ(p) (READ_AUDIO_STATUS(p)&0x1000) 220 + #define IS_MPUIRQ(p) (READ_AUDIO_STATUS(p)&0x2000) 221 + 222 + #define RESP 0x00000001 /* command flags */ 223 + #define PARM 0x00000002 224 + #define CMDA 0x00000004 225 + #define CMDB 0x00000008 226 + #define NILL 0x00000000 227 + 228 + #define LONG0(a) ((u32)a) /* shifts and masks */ 229 + #define BYTE0(a) (LONG0(a)&0xff) 230 + #define BYTE1(a) (BYTE0(a)<<8) 231 + #define BYTE2(a) (BYTE0(a)<<16) 232 + #define BYTE3(a) (BYTE0(a)<<24) 233 + #define WORD0(a) (LONG0(a)&0xffff) 234 + #define WORD1(a) (WORD0(a)<<8) 235 + #define WORD2(a) (WORD0(a)<<16) 236 + #define TRINIB0(a) (LONG0(a)&0xffffff) 237 + #define TRINIB1(a) (TRINIB0(a)<<8) 238 + 239 + #define RET(a) ((union cmdret *)(a)) 240 + 241 + #define SEND_GETV(p,b) sendcmd(p,RESP,GETV,0,RET(b)) /* get version */ 242 + #define SEND_GETC(p,b,c) sendcmd(p,PARM|RESP,GETC,c,RET(b)) 243 + #define SEND_GUNS(p,b) sendcmd(p,RESP,GUNS,0,RET(b)) 244 + #define SEND_SCID(p,b) sendcmd(p,RESP,SCID,0,RET(b)) 245 + #define SEND_RMEM(p,b,c,d) sendcmd(p,PARM|RESP,RMEM|BYTE1(b),LONG0(c),RET(d)) /* memory access for firmware write */ 246 + #define SEND_SMEM(p,b,c) sendcmd(p,PARM,SMEM|BYTE1(b),LONG0(c),RET(0)) /* memory access for firmware write */ 247 + #define SEND_WMEM(p,b,c) sendcmd(p,PARM,WMEM|BYTE1(b),LONG0(c),RET(0)) /* memory access for firmware write */ 248 + #define SEND_SDTM(p,b,c) sendcmd(p,PARM|RESP,SDTM|TRINIB1(b),0,RET(c)) /* memory access for firmware write */ 249 + #define SEND_GOTO(p,b) sendcmd(p,PARM,GOTO,LONG0(b),RET(0)) /* memory access for firmware write */ 250 + #define SEND_SETDPLL(p) sendcmd(p,0,ARM_SETDPLL,0,RET(0)) 251 + #define SEND_SSTR(p,b,c) sendcmd(p,PARM,SSTR|BYTE3(b),LONG0(c),RET(0)) /* start stream */ 252 + #define SEND_PSTR(p,b) sendcmd(p,PARM,PSTR,BYTE3(b),RET(0)) /* pause stream */ 253 + #define SEND_KSTR(p,b) sendcmd(p,PARM,KSTR,BYTE3(b),RET(0)) /* stop stream */ 254 + #define SEND_KDMA(p) sendcmd(p,0,KDMA,0,RET(0)) /* stop all dma */ 255 + #define SEND_GPOS(p,b,c,d) sendcmd(p,PARM|RESP,GPOS,BYTE3(c)|BYTE2(b),RET(d)) /* get position in dma */ 256 + #define SEND_SETF(p,b,c,d,e,f,g) sendcmd(p,PARM,SETF|WORD1(b)|BYTE3(c),d|BYTE1(e)|BYTE2(f)|BYTE3(g),RET(0)) /* set sample format at mixer */ 257 + #define SEND_GSTS(p,b,c,d) sendcmd(p,PARM|RESP,GSTS,BYTE3(c)|BYTE2(b),RET(d)) 258 + #define SEND_NGPOS(p,b,c,d) sendcmd(p,PARM|RESP,NGPOS,BYTE3(c)|BYTE2(b),RET(d)) 259 + #define SEND_PSEL(p,b,c) sendcmd(p,PARM,PSEL,BYTE2(b)|BYTE3(c),RET(0)) /* activate lbus path */ 260 + #define SEND_PCLR(p,b,c) sendcmd(p,PARM,PCLR,BYTE2(b)|BYTE3(c),RET(0)) /* deactivate lbus path */ 261 + #define SEND_PLST(p,b) sendcmd(p,PARM,PLST,BYTE3(b),RET(0)) 262 + #define SEND_RSSV(p,b,c,d) sendcmd(p,PARM|RESP,RSSV,BYTE2(b)|BYTE3(c),RET(d)) 263 + #define SEND_LSEL(p,b,c,d,e,f,g,h) sendcmd(p,PARM,LSEL|BYTE1(b)|BYTE2(c)|BYTE3(d),BYTE0(e)|BYTE1(f)|BYTE2(g)|BYTE3(h),RET(0)) /* select paths for internal connections */ 264 + #define SEND_SSRC(p,b,c,d,e) sendcmd(p,PARM,SSRC|BYTE1(b)|WORD2(c),WORD0(d)|WORD2(e),RET(0)) /* configure source */ 265 + #define SEND_SLST(p,b) sendcmd(p,PARM,SLST,BYTE3(b),RET(0)) 266 + #define SEND_RSRC(p,b,c) sendcmd(p,RESP,RSRC|BYTE1(b),0,RET(c)) /* read source config */ 267 + #define SEND_SSRB(p,b,c) sendcmd(p,PARM,SSRB|BYTE1(b),WORD2(c),RET(0)) 268 + #define SEND_SDGV(p,b,c,d,e) sendcmd(p,PARM,SDGV|BYTE2(b)|BYTE3(c),WORD0(d)|WORD2(e),RET(0)) /* set digital mixer */ 269 + #define SEND_RDGV(p,b,c,d) sendcmd(p,PARM|RESP,RDGV|BYTE2(b)|BYTE3(c),0,RET(d)) /* read digital mixer */ 270 + #define SEND_DLST(p,b) sendcmd(p,PARM,DLST,BYTE3(b),RET(0)) 271 + #define SEND_SACR(p,b,c) sendcmd(p,PARM,SACR,WORD0(b)|WORD2(c),RET(0)) /* set AC97 register */ 272 + #define SEND_RACR(p,b,c) sendcmd(p,PARM|RESP,RACR,WORD2(b),RET(c)) /* get AC97 register */ 273 + #define SEND_ALST(p,b) sendcmd(p,PARM,ALST,BYTE3(b),RET(0)) 274 + #define SEND_TXAC(p,b,c,d,e,f) sendcmd(p,PARM,TXAC|BYTE1(b)|WORD2(c),WORD0(d)|BYTE2(e)|BYTE3(f),RET(0)) 275 + #define SEND_RXAC(p,b,c,d) sendcmd(p,PARM|RESP,RXAC,BYTE2(b)|BYTE3(c),RET(d)) 276 + #define SEND_SI2S(p,b) sendcmd(p,PARM,SI2S,WORD2(b),RET(0)) 277 + 278 + #define EOB_STATUS 0x80000000 /* status flags : block boundary */ 279 + #define EOS_STATUS 0x40000000 /* : stoppped */ 280 + #define EOC_STATUS 0x20000000 /* : stream end */ 281 + #define ERR_STATUS 0x10000000 282 + #define EMPTY_STATUS 0x08000000 283 + 284 + #define IEOB_ENABLE 0x1 /* enable interrupts for status notification above */ 285 + #define IEOS_ENABLE 0x2 286 + #define IEOC_ENABLE 0x4 287 + #define RDONCE 0x8 288 + #define DESC_MAX_MASK 0xff 289 + 290 + #define ST_PLAY 0x1 /* stream states */ 291 + #define ST_STOP 0x2 292 + #define ST_PAUSE 0x4 293 + 294 + #define I2S_INTDEC 3 /* config for I2S link */ 295 + #define I2S_MERGER 0 296 + #define I2S_SPLITTER 0 297 + #define I2S_MIXER 7 298 + #define I2S_RATE 44100 299 + 300 + #define MODEM_INTDEC 4 /* config for modem link */ 301 + #define MODEM_MERGER 3 302 + #define MODEM_SPLITTER 0 303 + #define MODEM_MIXER 11 304 + 305 + #define FM_INTDEC 3 /* config for FM/OPL3 link */ 306 + #define FM_MERGER 0 307 + #define FM_SPLITTER 0 308 + #define FM_MIXER 9 309 + 310 + #define SPLIT_PATH 0x80 /* path splitting flag */ 311 + 312 + enum FIRMWARE { 313 + DATA_REC = 0, EXT_END_OF_FILE, EXT_SEG_ADDR_REC, EXT_GOTO_CMD_REC, 314 + EXT_LIN_ADDR_REC, 315 + }; 316 + 317 + enum CMDS { 318 + GETV = 0x00, GETC, GUNS, SCID, RMEM = 319 + 0x10, SMEM, WMEM, SDTM, GOTO, SSTR = 320 + 0x20, PSTR, KSTR, KDMA, GPOS, SETF, GSTS, NGPOS, PSEL = 321 + 0x30, PCLR, PLST, RSSV, LSEL, SSRC = 0x40, SLST, RSRC, SSRB, SDGV = 322 + 0x50, RDGV, DLST, SACR = 0x60, RACR, ALST, TXAC, RXAC, SI2S = 323 + 0x70, ARM_SETDPLL = 0x72, 324 + }; 325 + 326 + enum E1SOURCE { 327 + ARM2LBUS_FIFO0 = 0, ARM2LBUS_FIFO1, ARM2LBUS_FIFO2, ARM2LBUS_FIFO3, 328 + ARM2LBUS_FIFO4, ARM2LBUS_FIFO5, ARM2LBUS_FIFO6, ARM2LBUS_FIFO7, 329 + ARM2LBUS_FIFO8, ARM2LBUS_FIFO9, ARM2LBUS_FIFO10, ARM2LBUS_FIFO11, 330 + ARM2LBUS_FIFO12, ARM2LBUS_FIFO13, ARM2LBUS_FIFO14, ARM2LBUS_FIFO15, 331 + INTER0_OUT, INTER1_OUT, INTER2_OUT, INTER3_OUT, INTER4_OUT, 332 + INTERM0_OUT, INTERM1_OUT, INTERM2_OUT, INTERM3_OUT, INTERM4_OUT, 333 + INTERM5_OUT, INTERM6_OUT, DECIMM0_OUT, DECIMM1_OUT, DECIMM2_OUT, 334 + DECIMM3_OUT, DECIM0_OUT, SR3_4_OUT, OPL3_SAMPLE, ASRC0, ASRC1, 335 + ACLNK2PADC, ACLNK2MODEM0RX, ACLNK2MIC, ACLNK2MODEM1RX, ACLNK2HNDMIC, 336 + DIGITAL_MIXER_OUT0, GAINFUNC0_OUT, GAINFUNC1_OUT, GAINFUNC2_OUT, 337 + GAINFUNC3_OUT, GAINFUNC4_OUT, SOFTMODEMTX, SPLITTER0_OUTL, 338 + SPLITTER0_OUTR, SPLITTER1_OUTL, SPLITTER1_OUTR, SPLITTER2_OUTL, 339 + SPLITTER2_OUTR, SPLITTER3_OUTL, SPLITTER3_OUTR, MERGER0_OUT, 340 + MERGER1_OUT, MERGER2_OUT, MERGER3_OUT, ARM2LBUS_FIFO_DIRECT, NO_OUT 341 + }; 342 + 343 + enum E2SINK { 344 + LBUS2ARM_FIFO0 = 0, LBUS2ARM_FIFO1, LBUS2ARM_FIFO2, LBUS2ARM_FIFO3, 345 + LBUS2ARM_FIFO4, LBUS2ARM_FIFO5, LBUS2ARM_FIFO6, LBUS2ARM_FIFO7, 346 + INTER0_IN, INTER1_IN, INTER2_IN, INTER3_IN, INTER4_IN, INTERM0_IN, 347 + INTERM1_IN, INTERM2_IN, INTERM3_IN, INTERM4_IN, INTERM5_IN, INTERM6_IN, 348 + DECIMM0_IN, DECIMM1_IN, DECIMM2_IN, DECIMM3_IN, DECIM0_IN, SR3_4_IN, 349 + PDAC2ACLNK, MODEM0TX2ACLNK, MODEM1TX2ACLNK, HNDSPK2ACLNK, 350 + DIGITAL_MIXER_IN0, DIGITAL_MIXER_IN1, DIGITAL_MIXER_IN2, 351 + DIGITAL_MIXER_IN3, DIGITAL_MIXER_IN4, DIGITAL_MIXER_IN5, 352 + DIGITAL_MIXER_IN6, DIGITAL_MIXER_IN7, DIGITAL_MIXER_IN8, 353 + DIGITAL_MIXER_IN9, DIGITAL_MIXER_IN10, DIGITAL_MIXER_IN11, 354 + GAINFUNC0_IN, GAINFUNC1_IN, GAINFUNC2_IN, GAINFUNC3_IN, GAINFUNC4_IN, 355 + SOFTMODEMRX, SPLITTER0_IN, SPLITTER1_IN, SPLITTER2_IN, SPLITTER3_IN, 356 + MERGER0_INL, MERGER0_INR, MERGER1_INL, MERGER1_INR, MERGER2_INL, 357 + MERGER2_INR, MERGER3_INL, MERGER3_INR, E2SINK_MAX 358 + }; 359 + 360 + enum LBUS_SINK { 361 + LS_SRC_INTERPOLATOR = 0, LS_SRC_INTERPOLATORM, LS_SRC_DECIMATOR, 362 + LS_SRC_DECIMATORM, LS_MIXER_IN, LS_MIXER_GAIN_FUNCTION, 363 + LS_SRC_SPLITTER, LS_SRC_MERGER, LS_NONE1, LS_NONE2, 364 + }; 365 + 366 + enum RT_CHANNEL_IDS { 367 + M0TX = 0, M1TX, TAMTX, HSSPKR, PDAC, DSNDTX0, DSNDTX1, DSNDTX2, 368 + DSNDTX3, DSNDTX4, DSNDTX5, DSNDTX6, DSNDTX7, WVSTRTX, COP3DTX, SPARE, 369 + M0RX, HSMIC, M1RX, CLEANRX, MICADC, PADC, COPRX1, COPRX2, 370 + CHANNEL_ID_COUNTER 371 + }; 372 + 373 + enum { SB_CMD = 0, MODEM_CMD, I2S_CMD0, I2S_CMD1, FM_CMD, MAX_CMD }; 374 + 375 + struct lbuspath { 376 + unsigned char *noconv; 377 + unsigned char *stereo; 378 + unsigned char *mono; 379 + }; 380 + 381 + struct cmdport { 382 + u32 data1; /* cmd,param */ 383 + u32 data2; /* param */ 384 + u32 stat; /* status */ 385 + u32 pad[5]; 386 + }; 387 + 388 + struct riptideport { 389 + u32 audio_control; /* status registers */ 390 + u32 audio_status; 391 + u32 pad[2]; 392 + struct cmdport port[2]; /* command ports */ 393 + }; 394 + 395 + struct cmdif { 396 + struct riptideport *hwport; 397 + spinlock_t lock; 398 + unsigned int cmdcnt; /* cmd statistics */ 399 + unsigned int cmdtime; 400 + unsigned int cmdtimemax; 401 + unsigned int cmdtimemin; 402 + unsigned int errcnt; 403 + int is_reset; 404 + }; 405 + 406 + struct riptide_firmware { 407 + u16 ASIC; 408 + u16 CODEC; 409 + u16 AUXDSP; 410 + u16 PROG; 411 + }; 412 + 413 + union cmdret { 414 + u8 retbytes[8]; 415 + u16 retwords[4]; 416 + u32 retlongs[2]; 417 + }; 418 + 419 + union firmware_version { 420 + union cmdret ret; 421 + struct riptide_firmware firmware; 422 + }; 423 + 424 + #define get_pcmhwdev(substream) (struct pcmhw *)(substream->runtime->private_data) 425 + 426 + #define PLAYBACK_SUBSTREAMS 3 427 + struct snd_riptide { 428 + struct snd_card *card; 429 + struct pci_dev *pci; 430 + const struct firmware *fw_entry; 431 + 432 + struct cmdif *cif; 433 + 434 + struct snd_pcm *pcm; 435 + struct snd_pcm *pcm_i2s; 436 + struct snd_rawmidi *rmidi; 437 + struct snd_opl3 *opl3; 438 + struct snd_ac97 *ac97; 439 + struct snd_ac97_bus *ac97_bus; 440 + 441 + struct snd_pcm_substream *playback_substream[PLAYBACK_SUBSTREAMS]; 442 + struct snd_pcm_substream *capture_substream; 443 + 444 + int openstreams; 445 + 446 + int irq; 447 + unsigned long port; 448 + unsigned short mpuaddr; 449 + unsigned short opladdr; 450 + #ifdef SUPPORT_JOYSTICK 451 + unsigned short gameaddr; 452 + #endif 453 + struct resource *res_port; 454 + 455 + unsigned short device_id; 456 + 457 + union firmware_version firmware; 458 + 459 + spinlock_t lock; 460 + struct tasklet_struct riptide_tq; 461 + struct snd_info_entry *proc_entry; 462 + 463 + unsigned long received_irqs; 464 + unsigned long handled_irqs; 465 + #ifdef CONFIG_PM 466 + int in_suspend; 467 + #endif 468 + }; 469 + 470 + struct sgd { /* scatter gather desriptor */ 471 + u32 dwNextLink; 472 + u32 dwSegPtrPhys; 473 + u32 dwSegLen; 474 + u32 dwStat_Ctl; 475 + }; 476 + 477 + struct pcmhw { /* pcm descriptor */ 478 + struct lbuspath paths; 479 + unsigned char *lbuspath; 480 + unsigned char source; 481 + unsigned char intdec[2]; 482 + unsigned char mixer; 483 + unsigned char id; 484 + unsigned char state; 485 + unsigned int rate; 486 + unsigned int channels; 487 + snd_pcm_format_t format; 488 + struct snd_dma_buffer sgdlist; 489 + struct sgd *sgdbuf; 490 + unsigned int size; 491 + unsigned int pages; 492 + unsigned int oldpos; 493 + unsigned int pointer; 494 + }; 495 + 496 + #define CMDRET_ZERO (union cmdret){{(u32)0, (u32) 0}} 497 + 498 + static int sendcmd(struct cmdif *cif, u32 flags, u32 cmd, u32 parm, 499 + union cmdret *ret); 500 + static int getsourcesink(struct cmdif *cif, unsigned char source, 501 + unsigned char sink, unsigned char *a, 502 + unsigned char *b); 503 + static int snd_riptide_initialize(struct snd_riptide *chip); 504 + static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip); 505 + 506 + /* 507 + */ 508 + 509 + static struct pci_device_id snd_riptide_ids[] = { 510 + { 511 + .vendor = 0x127a,.device = 0x4310, 512 + .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 513 + }, 514 + { 515 + .vendor = 0x127a,.device = 0x4320, 516 + .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 517 + }, 518 + { 519 + .vendor = 0x127a,.device = 0x4330, 520 + .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 521 + }, 522 + { 523 + .vendor = 0x127a,.device = 0x4340, 524 + .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 525 + }, 526 + {0,}, 527 + }; 528 + 529 + #ifdef SUPPORT_JOYSTICK 530 + static struct pci_device_id snd_riptide_joystick_ids[] = { 531 + { 532 + .vendor = 0x127a,.device = 0x4312, 533 + .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 534 + }, 535 + { 536 + .vendor = 0x127a,.device = 0x4322, 537 + .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 538 + }, 539 + {.vendor = 0x127a,.device = 0x4332, 540 + .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 541 + }, 542 + {.vendor = 0x127a,.device = 0x4342, 543 + .subvendor = PCI_ANY_ID,.subdevice = PCI_ANY_ID, 544 + }, 545 + {0,}, 546 + }; 547 + #endif 548 + 549 + MODULE_DEVICE_TABLE(pci, snd_riptide_ids); 550 + 551 + /* 552 + */ 553 + 554 + static unsigned char lbusin2out[E2SINK_MAX + 1][2] = { 555 + {NO_OUT, LS_NONE1}, {NO_OUT, LS_NONE2}, {NO_OUT, LS_NONE1}, {NO_OUT, 556 + LS_NONE2}, 557 + {NO_OUT, LS_NONE1}, {NO_OUT, LS_NONE2}, {NO_OUT, LS_NONE1}, {NO_OUT, 558 + LS_NONE2}, 559 + {INTER0_OUT, LS_SRC_INTERPOLATOR}, {INTER1_OUT, LS_SRC_INTERPOLATOR}, 560 + {INTER2_OUT, LS_SRC_INTERPOLATOR}, {INTER3_OUT, LS_SRC_INTERPOLATOR}, 561 + {INTER4_OUT, LS_SRC_INTERPOLATOR}, {INTERM0_OUT, LS_SRC_INTERPOLATORM}, 562 + {INTERM1_OUT, LS_SRC_INTERPOLATORM}, {INTERM2_OUT, 563 + LS_SRC_INTERPOLATORM}, 564 + {INTERM3_OUT, LS_SRC_INTERPOLATORM}, {INTERM4_OUT, 565 + LS_SRC_INTERPOLATORM}, 566 + {INTERM5_OUT, LS_SRC_INTERPOLATORM}, {INTERM6_OUT, 567 + LS_SRC_INTERPOLATORM}, 568 + {DECIMM0_OUT, LS_SRC_DECIMATORM}, {DECIMM1_OUT, LS_SRC_DECIMATORM}, 569 + {DECIMM2_OUT, LS_SRC_DECIMATORM}, {DECIMM3_OUT, LS_SRC_DECIMATORM}, 570 + {DECIM0_OUT, LS_SRC_DECIMATOR}, {SR3_4_OUT, LS_NONE1}, {NO_OUT, 571 + LS_NONE2}, 572 + {NO_OUT, LS_NONE1}, {NO_OUT, LS_NONE2}, {NO_OUT, LS_NONE1}, 573 + {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 574 + {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 575 + {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 576 + {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 577 + {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 578 + {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, {DIGITAL_MIXER_OUT0, LS_MIXER_IN}, 579 + {GAINFUNC0_OUT, LS_MIXER_GAIN_FUNCTION}, {GAINFUNC1_OUT, 580 + LS_MIXER_GAIN_FUNCTION}, 581 + {GAINFUNC2_OUT, LS_MIXER_GAIN_FUNCTION}, {GAINFUNC3_OUT, 582 + LS_MIXER_GAIN_FUNCTION}, 583 + {GAINFUNC4_OUT, LS_MIXER_GAIN_FUNCTION}, {SOFTMODEMTX, LS_NONE1}, 584 + {SPLITTER0_OUTL, LS_SRC_SPLITTER}, {SPLITTER1_OUTL, LS_SRC_SPLITTER}, 585 + {SPLITTER2_OUTL, LS_SRC_SPLITTER}, {SPLITTER3_OUTL, LS_SRC_SPLITTER}, 586 + {MERGER0_OUT, LS_SRC_MERGER}, {MERGER0_OUT, LS_SRC_MERGER}, 587 + {MERGER1_OUT, LS_SRC_MERGER}, 588 + {MERGER1_OUT, LS_SRC_MERGER}, {MERGER2_OUT, LS_SRC_MERGER}, 589 + {MERGER2_OUT, LS_SRC_MERGER}, 590 + {MERGER3_OUT, LS_SRC_MERGER}, {MERGER3_OUT, LS_SRC_MERGER}, {NO_OUT, 591 + LS_NONE2}, 592 + }; 593 + 594 + static unsigned char lbus_play_opl3[] = { 595 + DIGITAL_MIXER_IN0 + FM_MIXER, 0xff 596 + }; 597 + static unsigned char lbus_play_modem[] = { 598 + DIGITAL_MIXER_IN0 + MODEM_MIXER, 0xff 599 + }; 600 + static unsigned char lbus_play_i2s[] = { 601 + INTER0_IN + I2S_INTDEC, DIGITAL_MIXER_IN0 + I2S_MIXER, 0xff 602 + }; 603 + static unsigned char lbus_play_out[] = { 604 + PDAC2ACLNK, 0xff 605 + }; 606 + static unsigned char lbus_play_outhp[] = { 607 + HNDSPK2ACLNK, 0xff 608 + }; 609 + static unsigned char lbus_play_noconv1[] = { 610 + DIGITAL_MIXER_IN0, 0xff 611 + }; 612 + static unsigned char lbus_play_stereo1[] = { 613 + INTER0_IN, DIGITAL_MIXER_IN0, 0xff 614 + }; 615 + static unsigned char lbus_play_mono1[] = { 616 + INTERM0_IN, DIGITAL_MIXER_IN0, 0xff 617 + }; 618 + static unsigned char lbus_play_noconv2[] = { 619 + DIGITAL_MIXER_IN1, 0xff 620 + }; 621 + static unsigned char lbus_play_stereo2[] = { 622 + INTER1_IN, DIGITAL_MIXER_IN1, 0xff 623 + }; 624 + static unsigned char lbus_play_mono2[] = { 625 + INTERM1_IN, DIGITAL_MIXER_IN1, 0xff 626 + }; 627 + static unsigned char lbus_play_noconv3[] = { 628 + DIGITAL_MIXER_IN2, 0xff 629 + }; 630 + static unsigned char lbus_play_stereo3[] = { 631 + INTER2_IN, DIGITAL_MIXER_IN2, 0xff 632 + }; 633 + static unsigned char lbus_play_mono3[] = { 634 + INTERM2_IN, DIGITAL_MIXER_IN2, 0xff 635 + }; 636 + static unsigned char lbus_rec_noconv1[] = { 637 + LBUS2ARM_FIFO5, 0xff 638 + }; 639 + static unsigned char lbus_rec_stereo1[] = { 640 + DECIM0_IN, LBUS2ARM_FIFO5, 0xff 641 + }; 642 + static unsigned char lbus_rec_mono1[] = { 643 + DECIMM3_IN, LBUS2ARM_FIFO5, 0xff 644 + }; 645 + 646 + static unsigned char play_ids[] = { 4, 1, 2, }; 647 + static unsigned char play_sources[] = { 648 + ARM2LBUS_FIFO4, ARM2LBUS_FIFO1, ARM2LBUS_FIFO2, 649 + }; 650 + static struct lbuspath lbus_play_paths[] = { 651 + { 652 + .noconv = lbus_play_noconv1, 653 + .stereo = lbus_play_stereo1, 654 + .mono = lbus_play_mono1, 655 + }, 656 + { 657 + .noconv = lbus_play_noconv2, 658 + .stereo = lbus_play_stereo2, 659 + .mono = lbus_play_mono2, 660 + }, 661 + { 662 + .noconv = lbus_play_noconv3, 663 + .stereo = lbus_play_stereo3, 664 + .mono = lbus_play_mono3, 665 + }, 666 + }; 667 + static struct lbuspath lbus_rec_path = { 668 + .noconv = lbus_rec_noconv1, 669 + .stereo = lbus_rec_stereo1, 670 + .mono = lbus_rec_mono1, 671 + }; 672 + 673 + #define FIRMWARE_VERSIONS 1 674 + static union firmware_version firmware_versions[] = { 675 + { 676 + .firmware.ASIC = 3,.firmware.CODEC = 2, 677 + .firmware.AUXDSP = 3,.firmware.PROG = 773, 678 + }, 679 + }; 680 + 681 + static u32 atoh(unsigned char *in, unsigned int len) 682 + { 683 + u32 sum = 0; 684 + unsigned int mult = 1; 685 + unsigned char c; 686 + 687 + while (len) { 688 + c = in[len - 1]; 689 + if ((c >= '0') && (c <= '9')) 690 + sum += mult * (c - '0'); 691 + else if ((c >= 'A') && (c <= 'F')) 692 + sum += mult * (c - ('A' - 10)); 693 + else if ((c >= 'a') && (c <= 'f')) 694 + sum += mult * (c - ('a' - 10)); 695 + mult *= 16; 696 + --len; 697 + } 698 + return sum; 699 + } 700 + 701 + static int senddata(struct cmdif *cif, unsigned char *in, u32 offset) 702 + { 703 + u32 addr; 704 + u32 data; 705 + u32 i; 706 + unsigned char *p; 707 + 708 + i = atoh(&in[1], 2); 709 + addr = offset + atoh(&in[3], 4); 710 + if (SEND_SMEM(cif, 0, addr) != 0) 711 + return -EACCES; 712 + p = in + 9; 713 + while (i) { 714 + data = atoh(p, 8); 715 + if (SEND_WMEM(cif, 2, 716 + ((data & 0x0f0f0f0f) << 4) | ((data & 0xf0f0f0f0) 717 + >> 4))) 718 + return -EACCES; 719 + i -= 4; 720 + p += 8; 721 + } 722 + return 0; 723 + } 724 + 725 + static int loadfirmware(struct cmdif *cif, unsigned char *img, 726 + unsigned int size) 727 + { 728 + unsigned char *in; 729 + u32 laddr, saddr, t, val; 730 + int err = 0; 731 + 732 + laddr = saddr = 0; 733 + while (size > 0 && err == 0) { 734 + in = img; 735 + if (in[0] == ':') { 736 + t = atoh(&in[7], 2); 737 + switch (t) { 738 + case DATA_REC: 739 + err = senddata(cif, in, laddr + saddr); 740 + break; 741 + case EXT_SEG_ADDR_REC: 742 + saddr = atoh(&in[9], 4) << 4; 743 + break; 744 + case EXT_LIN_ADDR_REC: 745 + laddr = atoh(&in[9], 4) << 16; 746 + break; 747 + case EXT_GOTO_CMD_REC: 748 + val = atoh(&in[9], 8); 749 + if (SEND_GOTO(cif, val) != 0) 750 + err = -EACCES; 751 + break; 752 + case EXT_END_OF_FILE: 753 + size = 0; 754 + break; 755 + default: 756 + break; 757 + } 758 + while (size > 0) { 759 + size--; 760 + if (*img++ == '\n') 761 + break; 762 + } 763 + } 764 + } 765 + snd_printdd("load firmware return %d\n", err); 766 + return err; 767 + } 768 + 769 + static void 770 + alloclbuspath(struct cmdif *cif, unsigned char source, 771 + unsigned char *path, unsigned char *mixer, unsigned char *s) 772 + { 773 + while (*path != 0xff) { 774 + unsigned char sink, type; 775 + 776 + sink = *path & (~SPLIT_PATH); 777 + if (sink != E2SINK_MAX) { 778 + snd_printdd("alloc path 0x%x->0x%x\n", source, sink); 779 + SEND_PSEL(cif, source, sink); 780 + source = lbusin2out[sink][0]; 781 + type = lbusin2out[sink][1]; 782 + if (type == LS_MIXER_IN) { 783 + if (mixer) 784 + *mixer = sink - DIGITAL_MIXER_IN0; 785 + } 786 + if (type == LS_SRC_DECIMATORM || 787 + type == LS_SRC_DECIMATOR || 788 + type == LS_SRC_INTERPOLATORM || 789 + type == LS_SRC_INTERPOLATOR) { 790 + if (s) { 791 + if (s[0] != 0xff) 792 + s[1] = sink; 793 + else 794 + s[0] = sink; 795 + } 796 + } 797 + } 798 + if (*path++ & SPLIT_PATH) { 799 + unsigned char *npath = path; 800 + 801 + while (*npath != 0xff) 802 + npath++; 803 + alloclbuspath(cif, source + 1, ++npath, mixer, s); 804 + } 805 + } 806 + } 807 + 808 + static void 809 + freelbuspath(struct cmdif *cif, unsigned char source, unsigned char *path) 810 + { 811 + while (*path != 0xff) { 812 + unsigned char sink; 813 + 814 + sink = *path & (~SPLIT_PATH); 815 + if (sink != E2SINK_MAX) { 816 + snd_printdd("free path 0x%x->0x%x\n", source, sink); 817 + SEND_PCLR(cif, source, sink); 818 + source = lbusin2out[sink][0]; 819 + } 820 + if (*path++ & SPLIT_PATH) { 821 + unsigned char *npath = path; 822 + 823 + while (*npath != 0xff) 824 + npath++; 825 + freelbuspath(cif, source + 1, ++npath); 826 + } 827 + } 828 + } 829 + 830 + static int writearm(struct cmdif *cif, u32 addr, u32 data, u32 mask) 831 + { 832 + union cmdret rptr = CMDRET_ZERO; 833 + unsigned int i = MAX_WRITE_RETRY; 834 + int flag = 1; 835 + 836 + SEND_RMEM(cif, 0x02, addr, &rptr); 837 + rptr.retlongs[0] &= (~mask); 838 + 839 + while (--i) { 840 + SEND_SMEM(cif, 0x01, addr); 841 + SEND_WMEM(cif, 0x02, (rptr.retlongs[0] | data)); 842 + SEND_RMEM(cif, 0x02, addr, &rptr); 843 + if ((rptr.retlongs[0] & data) == data) { 844 + flag = 0; 845 + break; 846 + } else 847 + rptr.retlongs[0] &= ~mask; 848 + } 849 + snd_printdd("send arm 0x%x 0x%x 0x%x return %d\n", addr, data, mask, 850 + flag); 851 + return flag; 852 + } 853 + 854 + static int sendcmd(struct cmdif *cif, u32 flags, u32 cmd, u32 parm, 855 + union cmdret *ret) 856 + { 857 + int i, j; 858 + int err; 859 + unsigned int time = 0; 860 + unsigned long irqflags; 861 + struct riptideport *hwport; 862 + struct cmdport *cmdport = NULL; 863 + 864 + snd_assert(cif, return -EINVAL); 865 + 866 + hwport = cif->hwport; 867 + if (cif->errcnt > MAX_ERROR_COUNT) { 868 + if (cif->is_reset) { 869 + snd_printk(KERN_ERR 870 + "Riptide: Too many failed cmds, reinitializing\n"); 871 + if (riptide_reset(cif, NULL) == 0) { 872 + cif->errcnt = 0; 873 + return -EIO; 874 + } 875 + } 876 + snd_printk(KERN_ERR "Riptide: Initialization failed.\n"); 877 + return -EINVAL; 878 + } 879 + if (ret) { 880 + ret->retlongs[0] = 0; 881 + ret->retlongs[1] = 0; 882 + } 883 + i = 0; 884 + spin_lock_irqsave(&cif->lock, irqflags); 885 + while (i++ < CMDIF_TIMEOUT && !IS_READY(cif->hwport)) 886 + udelay(10); 887 + if (i >= CMDIF_TIMEOUT) { 888 + err = -EBUSY; 889 + goto errout; 890 + } 891 + 892 + err = 0; 893 + for (j = 0, time = 0; time < CMDIF_TIMEOUT; j++, time += 2) { 894 + cmdport = &(hwport->port[j % 2]); 895 + if (IS_DATF(cmdport)) { /* free pending data */ 896 + READ_PORT_ULONG(cmdport->data1); 897 + READ_PORT_ULONG(cmdport->data2); 898 + } 899 + if (IS_CMDE(cmdport)) { 900 + if (flags & PARM) /* put data */ 901 + WRITE_PORT_ULONG(cmdport->data2, parm); 902 + WRITE_PORT_ULONG(cmdport->data1, cmd); /* write cmd */ 903 + if ((flags & RESP) && ret) { 904 + while (!IS_DATF(cmdport) && 905 + time++ < CMDIF_TIMEOUT) 906 + udelay(10); 907 + if (time < CMDIF_TIMEOUT) { /* read response */ 908 + ret->retlongs[0] = 909 + READ_PORT_ULONG(cmdport->data1); 910 + ret->retlongs[1] = 911 + READ_PORT_ULONG(cmdport->data2); 912 + } else { 913 + err = -ENOSYS; 914 + goto errout; 915 + } 916 + } 917 + break; 918 + } 919 + udelay(20); 920 + } 921 + if (time == CMDIF_TIMEOUT) { 922 + err = -ENODATA; 923 + goto errout; 924 + } 925 + spin_unlock_irqrestore(&cif->lock, irqflags); 926 + 927 + cif->cmdcnt++; /* update command statistics */ 928 + cif->cmdtime += time; 929 + if (time > cif->cmdtimemax) 930 + cif->cmdtimemax = time; 931 + if (time < cif->cmdtimemin) 932 + cif->cmdtimemin = time; 933 + if ((cif->cmdcnt) % 1000 == 0) 934 + snd_printdd 935 + ("send cmd %d time: %d mintime: %d maxtime %d err: %d\n", 936 + cif->cmdcnt, cif->cmdtime, cif->cmdtimemin, 937 + cif->cmdtimemax, cif->errcnt); 938 + return 0; 939 + 940 + errout: 941 + cif->errcnt++; 942 + spin_unlock_irqrestore(&cif->lock, irqflags); 943 + snd_printdd 944 + ("send cmd %d hw: 0x%x flag: 0x%x cmd: 0x%x parm: 0x%x ret: 0x%x 0x%x CMDE: %d DATF: %d failed %d\n", 945 + cif->cmdcnt, (int)((void *)&(cmdport->stat) - (void *)hwport), 946 + flags, cmd, parm, ret ? ret->retlongs[0] : 0, 947 + ret ? ret->retlongs[1] : 0, IS_CMDE(cmdport), IS_DATF(cmdport), 948 + err); 949 + return err; 950 + } 951 + 952 + static int 953 + setmixer(struct cmdif *cif, short num, unsigned short rval, unsigned short lval) 954 + { 955 + union cmdret rptr = CMDRET_ZERO; 956 + int i = 0; 957 + 958 + snd_printdd("sent mixer %d: 0x%d 0x%d\n", num, rval, lval); 959 + do { 960 + SEND_SDGV(cif, num, num, rval, lval); 961 + SEND_RDGV(cif, num, num, &rptr); 962 + if (rptr.retwords[0] == lval && rptr.retwords[1] == rval) 963 + return 0; 964 + } while (i++ < MAX_WRITE_RETRY); 965 + snd_printdd("sent mixer failed\n"); 966 + return -EIO; 967 + } 968 + 969 + static int getpaths(struct cmdif *cif, unsigned char *o) 970 + { 971 + unsigned char src[E2SINK_MAX]; 972 + unsigned char sink[E2SINK_MAX]; 973 + int i, j = 0; 974 + 975 + for (i = 0; i < E2SINK_MAX; i++) { 976 + getsourcesink(cif, i, i, &src[i], &sink[i]); 977 + if (sink[i] < E2SINK_MAX) { 978 + o[j++] = sink[i]; 979 + o[j++] = i; 980 + } 981 + } 982 + return j; 983 + } 984 + 985 + static int 986 + getsourcesink(struct cmdif *cif, unsigned char source, unsigned char sink, 987 + unsigned char *a, unsigned char *b) 988 + { 989 + union cmdret rptr = CMDRET_ZERO; 990 + 991 + if (SEND_RSSV(cif, source, sink, &rptr) && 992 + SEND_RSSV(cif, source, sink, &rptr)) 993 + return -EIO; 994 + *a = rptr.retbytes[0]; 995 + *b = rptr.retbytes[1]; 996 + snd_printdd("getsourcesink 0x%x 0x%x\n", *a, *b); 997 + return 0; 998 + } 999 + 1000 + static int 1001 + getsamplerate(struct cmdif *cif, unsigned char *intdec, unsigned int *rate) 1002 + { 1003 + unsigned char *s; 1004 + unsigned int p[2] = { 0, 0 }; 1005 + int i; 1006 + union cmdret rptr = CMDRET_ZERO; 1007 + 1008 + s = intdec; 1009 + for (i = 0; i < 2; i++) { 1010 + if (*s != 0xff) { 1011 + if (SEND_RSRC(cif, *s, &rptr) && 1012 + SEND_RSRC(cif, *s, &rptr)) 1013 + return -EIO; 1014 + p[i] += rptr.retwords[1]; 1015 + p[i] *= rptr.retwords[2]; 1016 + p[i] += rptr.retwords[3]; 1017 + p[i] /= 65536; 1018 + } 1019 + s++; 1020 + } 1021 + if (p[0]) { 1022 + if (p[1] != p[0]) 1023 + snd_printdd("rates differ %d %d\n", p[0], p[1]); 1024 + *rate = (unsigned int)p[0]; 1025 + } else 1026 + *rate = (unsigned int)p[1]; 1027 + snd_printdd("getsampleformat %d %d %d\n", intdec[0], intdec[1], *rate); 1028 + return 0; 1029 + } 1030 + 1031 + static int 1032 + setsampleformat(struct cmdif *cif, 1033 + unsigned char mixer, unsigned char id, 1034 + unsigned char channels, unsigned char format) 1035 + { 1036 + unsigned char w, ch, sig, order; 1037 + 1038 + snd_printdd 1039 + ("setsampleformat mixer: %d id: %d channels: %d format: %d\n", 1040 + mixer, id, channels, format); 1041 + ch = channels == 1; 1042 + w = snd_pcm_format_width(format) == 8; 1043 + sig = snd_pcm_format_unsigned(format) != 0; 1044 + order = snd_pcm_format_big_endian(format) != 0; 1045 + 1046 + if (SEND_SETF(cif, mixer, w, ch, order, sig, id) && 1047 + SEND_SETF(cif, mixer, w, ch, order, sig, id)) { 1048 + snd_printdd("setsampleformat failed\n"); 1049 + return -EIO; 1050 + } 1051 + return 0; 1052 + } 1053 + 1054 + static int 1055 + setsamplerate(struct cmdif *cif, unsigned char *intdec, unsigned int rate) 1056 + { 1057 + u32 D, M, N; 1058 + union cmdret rptr = CMDRET_ZERO; 1059 + int i; 1060 + 1061 + snd_printdd("setsamplerate intdec: %d,%d rate: %d\n", intdec[0], 1062 + intdec[1], rate); 1063 + D = 48000; 1064 + M = ((rate == 48000) ? 47999 : rate) * 65536; 1065 + N = M % D; 1066 + M /= D; 1067 + for (i = 0; i < 2; i++) { 1068 + if (*intdec != 0xff) { 1069 + do { 1070 + SEND_SSRC(cif, *intdec, D, M, N); 1071 + SEND_RSRC(cif, *intdec, &rptr); 1072 + } while (rptr.retwords[1] != D && 1073 + rptr.retwords[2] != M && 1074 + rptr.retwords[3] != N && 1075 + i++ < MAX_WRITE_RETRY); 1076 + if (i == MAX_WRITE_RETRY) { 1077 + snd_printdd("sent samplerate %d: %d failed\n", 1078 + *intdec, rate); 1079 + return -EIO; 1080 + } 1081 + } 1082 + intdec++; 1083 + } 1084 + return 0; 1085 + } 1086 + 1087 + static int 1088 + getmixer(struct cmdif *cif, short num, unsigned short *rval, 1089 + unsigned short *lval) 1090 + { 1091 + union cmdret rptr = CMDRET_ZERO; 1092 + 1093 + if (SEND_RDGV(cif, num, num, &rptr) && SEND_RDGV(cif, num, num, &rptr)) 1094 + return -EIO; 1095 + *rval = rptr.retwords[0]; 1096 + *lval = rptr.retwords[1]; 1097 + snd_printdd("got mixer %d: 0x%d 0x%d\n", num, *rval, *lval); 1098 + return 0; 1099 + } 1100 + 1101 + static void riptide_handleirq(unsigned long dev_id) 1102 + { 1103 + struct snd_riptide *chip = (void *)dev_id; 1104 + struct cmdif *cif = chip->cif; 1105 + struct snd_pcm_substream *substream[PLAYBACK_SUBSTREAMS + 1]; 1106 + struct snd_pcm_runtime *runtime; 1107 + struct pcmhw *data = NULL; 1108 + unsigned int pos, period_bytes; 1109 + struct sgd *c; 1110 + int i, j; 1111 + unsigned int flag; 1112 + 1113 + if (!cif) 1114 + return; 1115 + 1116 + for (i = 0; i < PLAYBACK_SUBSTREAMS; i++) 1117 + substream[i] = chip->playback_substream[i]; 1118 + substream[i] = chip->capture_substream; 1119 + for (i = 0; i < PLAYBACK_SUBSTREAMS + 1; i++) { 1120 + if (substream[i] && 1121 + (runtime = substream[i]->runtime) && 1122 + (data = runtime->private_data) && data->state != ST_STOP) { 1123 + pos = 0; 1124 + for (j = 0; j < data->pages; j++) { 1125 + c = &data->sgdbuf[j]; 1126 + flag = le32_to_cpu(c->dwStat_Ctl); 1127 + if (flag & EOB_STATUS) 1128 + pos += le32_to_cpu(c->dwSegLen); 1129 + if (flag & EOC_STATUS) 1130 + pos += le32_to_cpu(c->dwSegLen); 1131 + if ((flag & EOS_STATUS) 1132 + && (data->state == ST_PLAY)) { 1133 + data->state = ST_STOP; 1134 + snd_printk(KERN_ERR 1135 + "Riptide: DMA stopped unexpectedly\n"); 1136 + } 1137 + c->dwStat_Ctl = 1138 + cpu_to_le32(flag & 1139 + ~(EOS_STATUS | EOB_STATUS | 1140 + EOC_STATUS)); 1141 + } 1142 + data->pointer += pos; 1143 + pos += data->oldpos; 1144 + if (data->state != ST_STOP) { 1145 + period_bytes = 1146 + frames_to_bytes(runtime, 1147 + runtime->period_size); 1148 + snd_printdd 1149 + ("interrupt 0x%x after 0x%lx of 0x%lx frames in period\n", 1150 + READ_AUDIO_STATUS(cif->hwport), 1151 + bytes_to_frames(runtime, pos), 1152 + runtime->period_size); 1153 + j = 0; 1154 + if (pos >= period_bytes) { 1155 + j++; 1156 + while (pos >= period_bytes) 1157 + pos -= period_bytes; 1158 + } 1159 + data->oldpos = pos; 1160 + if (j > 0) 1161 + snd_pcm_period_elapsed(substream[i]); 1162 + } 1163 + } 1164 + } 1165 + } 1166 + 1167 + #ifdef CONFIG_PM 1168 + static int riptide_suspend(struct pci_dev *pci, pm_message_t state) 1169 + { 1170 + struct snd_card *card = pci_get_drvdata(pci); 1171 + struct snd_riptide *chip = card->private_data; 1172 + 1173 + chip->in_suspend = 1; 1174 + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 1175 + snd_pcm_suspend_all(chip->pcm); 1176 + snd_ac97_suspend(chip->ac97); 1177 + pci_set_power_state(pci, PCI_D3hot); 1178 + pci_disable_device(pci); 1179 + pci_save_state(pci); 1180 + return 0; 1181 + } 1182 + 1183 + static int riptide_resume(struct pci_dev *pci) 1184 + { 1185 + struct snd_card *card = pci_get_drvdata(pci); 1186 + struct snd_riptide *chip = card->private_data; 1187 + 1188 + pci_restore_state(pci); 1189 + pci_enable_device(pci); 1190 + pci_set_power_state(pci, PCI_D0); 1191 + pci_set_master(pci); 1192 + snd_riptide_initialize(chip); 1193 + snd_ac97_resume(chip->ac97); 1194 + snd_power_change_state(card, SNDRV_CTL_POWER_D0); 1195 + chip->in_suspend = 0; 1196 + return 0; 1197 + } 1198 + #endif 1199 + 1200 + static int riptide_reset(struct cmdif *cif, struct snd_riptide *chip) 1201 + { 1202 + int timeout, tries; 1203 + union cmdret rptr = CMDRET_ZERO; 1204 + union firmware_version firmware; 1205 + int i, j, err, has_firmware; 1206 + 1207 + if (!cif) 1208 + return -EINVAL; 1209 + 1210 + cif->cmdcnt = 0; 1211 + cif->cmdtime = 0; 1212 + cif->cmdtimemax = 0; 1213 + cif->cmdtimemin = 0xffffffff; 1214 + cif->errcnt = 0; 1215 + cif->is_reset = 0; 1216 + 1217 + tries = RESET_TRIES; 1218 + has_firmware = 0; 1219 + while (has_firmware == 0 && tries-- > 0) { 1220 + for (i = 0; i < 2; i++) { 1221 + WRITE_PORT_ULONG(cif->hwport->port[i].data1, 0); 1222 + WRITE_PORT_ULONG(cif->hwport->port[i].data2, 0); 1223 + } 1224 + SET_GRESET(cif->hwport); 1225 + udelay(100); 1226 + UNSET_GRESET(cif->hwport); 1227 + udelay(100); 1228 + 1229 + for (timeout = 100000; --timeout; udelay(10)) { 1230 + if (IS_READY(cif->hwport) && !IS_GERR(cif->hwport)) 1231 + break; 1232 + } 1233 + if (timeout == 0) { 1234 + snd_printk(KERN_ERR 1235 + "Riptide: device not ready, audio status: 0x%x ready: %d gerr: %d\n", 1236 + READ_AUDIO_STATUS(cif->hwport), 1237 + IS_READY(cif->hwport), IS_GERR(cif->hwport)); 1238 + return -EIO; 1239 + } else { 1240 + snd_printdd 1241 + ("Riptide: audio status: 0x%x ready: %d gerr: %d\n", 1242 + READ_AUDIO_STATUS(cif->hwport), 1243 + IS_READY(cif->hwport), IS_GERR(cif->hwport)); 1244 + } 1245 + 1246 + SEND_GETV(cif, &rptr); 1247 + for (i = 0; i < 4; i++) 1248 + firmware.ret.retwords[i] = rptr.retwords[i]; 1249 + 1250 + snd_printdd 1251 + ("Firmware version: ASIC: %d CODEC %d AUXDSP %d PROG %d\n", 1252 + firmware.firmware.ASIC, firmware.firmware.CODEC, 1253 + firmware.firmware.AUXDSP, firmware.firmware.PROG); 1254 + 1255 + for (j = 0; j < FIRMWARE_VERSIONS; j++) { 1256 + has_firmware = 1; 1257 + for (i = 0; i < 4; i++) { 1258 + if (firmware_versions[j].ret.retwords[i] != 1259 + firmware.ret.retwords[i]) 1260 + has_firmware = 0; 1261 + } 1262 + if (has_firmware) 1263 + break; 1264 + } 1265 + 1266 + if (chip != NULL && has_firmware == 0) { 1267 + snd_printdd("Writing Firmware\n"); 1268 + if (!chip->fw_entry) { 1269 + if ((err = 1270 + request_firmware(&chip->fw_entry, 1271 + "riptide.hex", 1272 + &chip->pci->dev)) != 0) { 1273 + snd_printk(KERN_ERR 1274 + "Riptide: Firmware not available %d\n", 1275 + err); 1276 + return -EIO; 1277 + } 1278 + } 1279 + err = loadfirmware(cif, chip->fw_entry->data, 1280 + chip->fw_entry->size); 1281 + if (err) 1282 + snd_printk(KERN_ERR 1283 + "Riptide: Could not load firmware %d\n", 1284 + err); 1285 + } 1286 + } 1287 + 1288 + SEND_SACR(cif, 0, AC97_RESET); 1289 + SEND_RACR(cif, AC97_RESET, &rptr); 1290 + snd_printdd("AC97: 0x%x 0x%x\n", rptr.retlongs[0], rptr.retlongs[1]); 1291 + 1292 + SEND_PLST(cif, 0); 1293 + SEND_SLST(cif, 0); 1294 + SEND_DLST(cif, 0); 1295 + SEND_ALST(cif, 0); 1296 + SEND_KDMA(cif); 1297 + 1298 + writearm(cif, 0x301F8, 1, 1); 1299 + writearm(cif, 0x301F4, 1, 1); 1300 + 1301 + SEND_LSEL(cif, MODEM_CMD, 0, 0, MODEM_INTDEC, MODEM_MERGER, 1302 + MODEM_SPLITTER, MODEM_MIXER); 1303 + setmixer(cif, MODEM_MIXER, 0x7fff, 0x7fff); 1304 + alloclbuspath(cif, ARM2LBUS_FIFO13, lbus_play_modem, NULL, NULL); 1305 + 1306 + SEND_LSEL(cif, FM_CMD, 0, 0, FM_INTDEC, FM_MERGER, FM_SPLITTER, 1307 + FM_MIXER); 1308 + setmixer(cif, FM_MIXER, 0x7fff, 0x7fff); 1309 + writearm(cif, 0x30648 + FM_MIXER * 4, 0x01, 0x00000005); 1310 + writearm(cif, 0x301A8, 0x02, 0x00000002); 1311 + writearm(cif, 0x30264, 0x08, 0xffffffff); 1312 + alloclbuspath(cif, OPL3_SAMPLE, lbus_play_opl3, NULL, NULL); 1313 + 1314 + SEND_SSRC(cif, I2S_INTDEC, 48000, 1315 + ((u32) I2S_RATE * 65536) / 48000, 1316 + ((u32) I2S_RATE * 65536) % 48000); 1317 + SEND_LSEL(cif, I2S_CMD0, 0, 0, I2S_INTDEC, I2S_MERGER, I2S_SPLITTER, 1318 + I2S_MIXER); 1319 + SEND_SI2S(cif, 1); 1320 + alloclbuspath(cif, ARM2LBUS_FIFO0, lbus_play_i2s, NULL, NULL); 1321 + alloclbuspath(cif, DIGITAL_MIXER_OUT0, lbus_play_out, NULL, NULL); 1322 + alloclbuspath(cif, DIGITAL_MIXER_OUT0, lbus_play_outhp, NULL, NULL); 1323 + 1324 + SET_AIACK(cif->hwport); 1325 + SET_AIE(cif->hwport); 1326 + SET_AIACK(cif->hwport); 1327 + cif->is_reset = 1; 1328 + if (chip) { 1329 + for (i = 0; i < 4; i++) 1330 + chip->firmware.ret.retwords[i] = 1331 + firmware.ret.retwords[i]; 1332 + } 1333 + 1334 + return 0; 1335 + } 1336 + 1337 + static struct snd_pcm_hardware snd_riptide_playback = { 1338 + .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1339 + SNDRV_PCM_INFO_BLOCK_TRANSFER | 1340 + SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID), 1341 + .formats = 1342 + SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 1343 + | SNDRV_PCM_FMTBIT_U16_LE, 1344 + .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, 1345 + .rate_min = 5500, 1346 + .rate_max = 48000, 1347 + .channels_min = 1, 1348 + .channels_max = 2, 1349 + .buffer_bytes_max = (64 * 1024), 1350 + .period_bytes_min = PAGE_SIZE >> 1, 1351 + .period_bytes_max = PAGE_SIZE << 8, 1352 + .periods_min = 2, 1353 + .periods_max = 64, 1354 + .fifo_size = 0, 1355 + }; 1356 + static struct snd_pcm_hardware snd_riptide_capture = { 1357 + .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1358 + SNDRV_PCM_INFO_BLOCK_TRANSFER | 1359 + SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID), 1360 + .formats = 1361 + SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 1362 + | SNDRV_PCM_FMTBIT_U16_LE, 1363 + .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, 1364 + .rate_min = 5500, 1365 + .rate_max = 48000, 1366 + .channels_min = 1, 1367 + .channels_max = 2, 1368 + .buffer_bytes_max = (64 * 1024), 1369 + .period_bytes_min = PAGE_SIZE >> 1, 1370 + .period_bytes_max = PAGE_SIZE << 3, 1371 + .periods_min = 2, 1372 + .periods_max = 64, 1373 + .fifo_size = 0, 1374 + }; 1375 + 1376 + static snd_pcm_uframes_t snd_riptide_pointer(struct snd_pcm_substream 1377 + *substream) 1378 + { 1379 + struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1380 + struct snd_pcm_runtime *runtime = substream->runtime; 1381 + struct pcmhw *data = get_pcmhwdev(substream); 1382 + struct cmdif *cif = chip->cif; 1383 + union cmdret rptr = CMDRET_ZERO; 1384 + snd_pcm_uframes_t ret; 1385 + 1386 + SEND_GPOS(cif, 0, data->id, &rptr); 1387 + if (data->size && runtime->period_size) { 1388 + snd_printdd 1389 + ("pointer stream %d position 0x%x(0x%x in buffer) bytes 0x%lx(0x%lx in period) frames\n", 1390 + data->id, rptr.retlongs[1], rptr.retlongs[1] % data->size, 1391 + bytes_to_frames(runtime, rptr.retlongs[1]), 1392 + bytes_to_frames(runtime, 1393 + rptr.retlongs[1]) % runtime->period_size); 1394 + if (rptr.retlongs[1] > data->pointer) 1395 + ret = 1396 + bytes_to_frames(runtime, 1397 + rptr.retlongs[1] % data->size); 1398 + else 1399 + ret = 1400 + bytes_to_frames(runtime, 1401 + data->pointer % data->size); 1402 + } else { 1403 + snd_printdd("stream not started or strange parms (%d %ld)\n", 1404 + data->size, runtime->period_size); 1405 + ret = bytes_to_frames(runtime, 0); 1406 + } 1407 + return ret; 1408 + } 1409 + 1410 + static int snd_riptide_trigger(struct snd_pcm_substream *substream, int cmd) 1411 + { 1412 + int i, j; 1413 + struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1414 + struct pcmhw *data = get_pcmhwdev(substream); 1415 + struct cmdif *cif = chip->cif; 1416 + union cmdret rptr = CMDRET_ZERO; 1417 + 1418 + spin_lock(&chip->lock); 1419 + switch (cmd) { 1420 + case SNDRV_PCM_TRIGGER_START: 1421 + case SNDRV_PCM_TRIGGER_RESUME: 1422 + if (!(data->state & ST_PLAY)) { 1423 + SEND_SSTR(cif, data->id, data->sgdlist.addr); 1424 + SET_AIE(cif->hwport); 1425 + data->state = ST_PLAY; 1426 + if (data->mixer != 0xff) 1427 + setmixer(cif, data->mixer, 0x7fff, 0x7fff); 1428 + chip->openstreams++; 1429 + data->oldpos = 0; 1430 + data->pointer = 0; 1431 + } 1432 + break; 1433 + case SNDRV_PCM_TRIGGER_STOP: 1434 + case SNDRV_PCM_TRIGGER_SUSPEND: 1435 + if (data->mixer != 0xff) 1436 + setmixer(cif, data->mixer, 0, 0); 1437 + setmixer(cif, data->mixer, 0, 0); 1438 + SEND_KSTR(cif, data->id); 1439 + data->state = ST_STOP; 1440 + chip->openstreams--; 1441 + j = 0; 1442 + do { 1443 + i = rptr.retlongs[1]; 1444 + SEND_GPOS(cif, 0, data->id, &rptr); 1445 + udelay(1); 1446 + } while (i != rptr.retlongs[1] && j++ < MAX_WRITE_RETRY); 1447 + if (j >= MAX_WRITE_RETRY) 1448 + snd_printk(KERN_ERR "Riptide: Could not stop stream!"); 1449 + break; 1450 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1451 + if (!(data->state & ST_PAUSE)) { 1452 + SEND_PSTR(cif, data->id); 1453 + data->state |= ST_PAUSE; 1454 + chip->openstreams--; 1455 + } 1456 + break; 1457 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1458 + if (data->state & ST_PAUSE) { 1459 + SEND_SSTR(cif, data->id, data->sgdlist.addr); 1460 + data->state &= ~ST_PAUSE; 1461 + chip->openstreams++; 1462 + } 1463 + break; 1464 + default: 1465 + spin_unlock(&chip->lock); 1466 + return -EINVAL; 1467 + } 1468 + spin_unlock(&chip->lock); 1469 + return 0; 1470 + } 1471 + 1472 + static int snd_riptide_prepare(struct snd_pcm_substream *substream) 1473 + { 1474 + struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1475 + struct snd_pcm_runtime *runtime = substream->runtime; 1476 + struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream); 1477 + struct pcmhw *data = get_pcmhwdev(substream); 1478 + struct cmdif *cif = chip->cif; 1479 + unsigned char *lbuspath = NULL; 1480 + unsigned int rate, channels; 1481 + int err = 0; 1482 + snd_pcm_format_t format; 1483 + 1484 + snd_assert(cif && data, return -EINVAL); 1485 + 1486 + snd_printdd("prepare id %d ch: %d f:0x%x r:%d\n", data->id, 1487 + runtime->channels, runtime->format, runtime->rate); 1488 + 1489 + spin_lock_irq(&chip->lock); 1490 + channels = runtime->channels; 1491 + format = runtime->format; 1492 + rate = runtime->rate; 1493 + switch (channels) { 1494 + case 1: 1495 + if (rate == 48000 && format == SNDRV_PCM_FORMAT_S16_LE) 1496 + lbuspath = data->paths.noconv; 1497 + else 1498 + lbuspath = data->paths.mono; 1499 + break; 1500 + case 2: 1501 + if (rate == 48000 && format == SNDRV_PCM_FORMAT_S16_LE) 1502 + lbuspath = data->paths.noconv; 1503 + else 1504 + lbuspath = data->paths.stereo; 1505 + break; 1506 + } 1507 + snd_printdd("use sgdlist at 0x%p and buffer at 0x%p\n", 1508 + data->sgdlist.area, sgbuf); 1509 + if (data->sgdlist.area && sgbuf) { 1510 + unsigned int i, j, size, pages, f, pt, period; 1511 + struct sgd *c, *p = NULL; 1512 + 1513 + size = frames_to_bytes(runtime, runtime->buffer_size); 1514 + period = frames_to_bytes(runtime, runtime->period_size); 1515 + f = PAGE_SIZE; 1516 + while ((size + (f >> 1) - 1) <= (f << 7) && (f << 1) > period) 1517 + f = f >> 1; 1518 + pages = (size + f - 1) / f; 1519 + data->size = size; 1520 + data->pages = pages; 1521 + snd_printdd 1522 + ("create sgd size: 0x%x pages %d of size 0x%x for period 0x%x\n", 1523 + size, pages, f, period); 1524 + pt = 0; 1525 + j = 0; 1526 + for (i = 0; i < pages; i++) { 1527 + c = &data->sgdbuf[i]; 1528 + if (p) 1529 + p->dwNextLink = cpu_to_le32(data->sgdlist.addr + 1530 + (i * 1531 + sizeof(struct 1532 + sgd))); 1533 + c->dwNextLink = cpu_to_le32(data->sgdlist.addr); 1534 + c->dwSegPtrPhys = 1535 + cpu_to_le32(sgbuf->table[j].addr + pt); 1536 + pt = (pt + f) % PAGE_SIZE; 1537 + if (pt == 0) 1538 + j++; 1539 + c->dwSegLen = cpu_to_le32(f); 1540 + c->dwStat_Ctl = 1541 + cpu_to_le32(IEOB_ENABLE | IEOS_ENABLE | 1542 + IEOC_ENABLE); 1543 + p = c; 1544 + size -= f; 1545 + } 1546 + data->sgdbuf[i].dwSegLen = cpu_to_le32(size); 1547 + } 1548 + if (lbuspath && lbuspath != data->lbuspath) { 1549 + if (data->lbuspath) 1550 + freelbuspath(cif, data->source, data->lbuspath); 1551 + alloclbuspath(cif, data->source, lbuspath, 1552 + &data->mixer, data->intdec); 1553 + data->lbuspath = lbuspath; 1554 + data->rate = 0; 1555 + } 1556 + if (data->rate != rate || data->format != format || 1557 + data->channels != channels) { 1558 + data->rate = rate; 1559 + data->format = format; 1560 + data->channels = channels; 1561 + if (setsampleformat 1562 + (cif, data->mixer, data->id, channels, format) 1563 + || setsamplerate(cif, data->intdec, rate)) 1564 + err = -EIO; 1565 + } 1566 + spin_unlock_irq(&chip->lock); 1567 + return err; 1568 + } 1569 + 1570 + static int 1571 + snd_riptide_hw_params(struct snd_pcm_substream *substream, 1572 + struct snd_pcm_hw_params *hw_params) 1573 + { 1574 + struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1575 + struct pcmhw *data = get_pcmhwdev(substream); 1576 + struct snd_dma_buffer *sgdlist = &data->sgdlist; 1577 + int err; 1578 + 1579 + snd_printdd("hw params id %d (sgdlist: 0x%p 0x%lx %d)\n", data->id, 1580 + sgdlist->area, (unsigned long)sgdlist->addr, 1581 + (int)sgdlist->bytes); 1582 + if (sgdlist->area) 1583 + snd_dma_free_pages(sgdlist); 1584 + if ((err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 1585 + snd_dma_pci_data(chip->pci), 1586 + sizeof(struct sgd) * (DESC_MAX_MASK + 1), 1587 + sgdlist)) < 0) { 1588 + snd_printk(KERN_ERR "Riptide: failed to alloc %d dma bytes\n", 1589 + (int)sizeof(struct sgd) * (DESC_MAX_MASK + 1)); 1590 + return err; 1591 + } 1592 + data->sgdbuf = (struct sgd *)sgdlist->area; 1593 + return snd_pcm_lib_malloc_pages(substream, 1594 + params_buffer_bytes(hw_params)); 1595 + } 1596 + 1597 + static int snd_riptide_hw_free(struct snd_pcm_substream *substream) 1598 + { 1599 + struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1600 + struct pcmhw *data = get_pcmhwdev(substream); 1601 + struct cmdif *cif = chip->cif; 1602 + 1603 + if (cif && data) { 1604 + if (data->lbuspath) 1605 + freelbuspath(cif, data->source, data->lbuspath); 1606 + data->lbuspath = NULL; 1607 + data->source = 0xff; 1608 + data->intdec[0] = 0xff; 1609 + data->intdec[1] = 0xff; 1610 + 1611 + if (data->sgdlist.area) { 1612 + snd_dma_free_pages(&data->sgdlist); 1613 + data->sgdlist.area = NULL; 1614 + } 1615 + } 1616 + return snd_pcm_lib_free_pages(substream); 1617 + } 1618 + 1619 + static int snd_riptide_playback_open(struct snd_pcm_substream *substream) 1620 + { 1621 + struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1622 + struct snd_pcm_runtime *runtime = substream->runtime; 1623 + struct pcmhw *data; 1624 + int index = substream->number; 1625 + 1626 + chip->playback_substream[index] = substream; 1627 + runtime->hw = snd_riptide_playback; 1628 + data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL); 1629 + data->paths = lbus_play_paths[index]; 1630 + data->id = play_ids[index]; 1631 + data->source = play_sources[index]; 1632 + data->intdec[0] = 0xff; 1633 + data->intdec[1] = 0xff; 1634 + data->state = ST_STOP; 1635 + runtime->private_data = data; 1636 + return snd_pcm_hw_constraint_integer(runtime, 1637 + SNDRV_PCM_HW_PARAM_PERIODS); 1638 + } 1639 + 1640 + static int snd_riptide_capture_open(struct snd_pcm_substream *substream) 1641 + { 1642 + struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1643 + struct snd_pcm_runtime *runtime = substream->runtime; 1644 + struct pcmhw *data; 1645 + 1646 + chip->capture_substream = substream; 1647 + runtime->hw = snd_riptide_capture; 1648 + data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL); 1649 + data->paths = lbus_rec_path; 1650 + data->id = PADC; 1651 + data->source = ACLNK2PADC; 1652 + data->intdec[0] = 0xff; 1653 + data->intdec[1] = 0xff; 1654 + data->state = ST_STOP; 1655 + runtime->private_data = data; 1656 + return snd_pcm_hw_constraint_integer(runtime, 1657 + SNDRV_PCM_HW_PARAM_PERIODS); 1658 + } 1659 + 1660 + static int snd_riptide_playback_close(struct snd_pcm_substream *substream) 1661 + { 1662 + struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1663 + struct pcmhw *data = get_pcmhwdev(substream); 1664 + int index = substream->number; 1665 + 1666 + substream->runtime->private_data = NULL; 1667 + chip->playback_substream[index] = NULL; 1668 + kfree(data); 1669 + return 0; 1670 + } 1671 + 1672 + static int snd_riptide_capture_close(struct snd_pcm_substream *substream) 1673 + { 1674 + struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1675 + struct pcmhw *data = get_pcmhwdev(substream); 1676 + 1677 + substream->runtime->private_data = NULL; 1678 + chip->capture_substream = NULL; 1679 + kfree(data); 1680 + return 0; 1681 + } 1682 + 1683 + static struct snd_pcm_ops snd_riptide_playback_ops = { 1684 + .open = snd_riptide_playback_open, 1685 + .close = snd_riptide_playback_close, 1686 + .ioctl = snd_pcm_lib_ioctl, 1687 + .hw_params = snd_riptide_hw_params, 1688 + .hw_free = snd_riptide_hw_free, 1689 + .prepare = snd_riptide_prepare, 1690 + .page = snd_pcm_sgbuf_ops_page, 1691 + .trigger = snd_riptide_trigger, 1692 + .pointer = snd_riptide_pointer, 1693 + }; 1694 + static struct snd_pcm_ops snd_riptide_capture_ops = { 1695 + .open = snd_riptide_capture_open, 1696 + .close = snd_riptide_capture_close, 1697 + .ioctl = snd_pcm_lib_ioctl, 1698 + .hw_params = snd_riptide_hw_params, 1699 + .hw_free = snd_riptide_hw_free, 1700 + .prepare = snd_riptide_prepare, 1701 + .page = snd_pcm_sgbuf_ops_page, 1702 + .trigger = snd_riptide_trigger, 1703 + .pointer = snd_riptide_pointer, 1704 + }; 1705 + 1706 + static int __devinit 1707 + snd_riptide_pcm(struct snd_riptide *chip, int device, struct snd_pcm **rpcm) 1708 + { 1709 + struct snd_pcm *pcm; 1710 + int err; 1711 + 1712 + if (rpcm) 1713 + *rpcm = NULL; 1714 + if ((err = 1715 + snd_pcm_new(chip->card, "RIPTIDE", device, PLAYBACK_SUBSTREAMS, 1, 1716 + &pcm)) < 0) 1717 + return err; 1718 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, 1719 + &snd_riptide_playback_ops); 1720 + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 1721 + &snd_riptide_capture_ops); 1722 + pcm->private_data = chip; 1723 + pcm->info_flags = 0; 1724 + strcpy(pcm->name, "RIPTIDE"); 1725 + chip->pcm = pcm; 1726 + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1727 + snd_dma_pci_data(chip->pci), 1728 + 64 * 1024, 128 * 1024); 1729 + if (rpcm) 1730 + *rpcm = pcm; 1731 + return 0; 1732 + } 1733 + 1734 + static irqreturn_t 1735 + snd_riptide_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1736 + { 1737 + struct snd_riptide *chip = dev_id; 1738 + struct cmdif *cif = chip->cif; 1739 + 1740 + if (cif) { 1741 + chip->received_irqs++; 1742 + if (IS_EOBIRQ(cif->hwport) || IS_EOSIRQ(cif->hwport) || 1743 + IS_EOCIRQ(cif->hwport)) { 1744 + chip->handled_irqs++; 1745 + tasklet_hi_schedule(&chip->riptide_tq); 1746 + } 1747 + if (chip->rmidi && IS_MPUIRQ(cif->hwport)) { 1748 + chip->handled_irqs++; 1749 + snd_mpu401_uart_interrupt(irq, 1750 + chip->rmidi->private_data, 1751 + regs); 1752 + } 1753 + SET_AIACK(cif->hwport); 1754 + } 1755 + return IRQ_HANDLED; 1756 + } 1757 + 1758 + static void 1759 + snd_riptide_codec_write(struct snd_ac97 *ac97, unsigned short reg, 1760 + unsigned short val) 1761 + { 1762 + struct snd_riptide *chip = ac97->private_data; 1763 + struct cmdif *cif = chip->cif; 1764 + union cmdret rptr = CMDRET_ZERO; 1765 + int i = 0; 1766 + 1767 + snd_assert(cif, return); 1768 + 1769 + snd_printdd("Write AC97 reg 0x%x 0x%x\n", reg, val); 1770 + do { 1771 + SEND_SACR(cif, val, reg); 1772 + SEND_RACR(cif, reg, &rptr); 1773 + } while (rptr.retwords[1] != val && i++ < MAX_WRITE_RETRY); 1774 + if (i == MAX_WRITE_RETRY) 1775 + snd_printdd("Write AC97 reg failed\n"); 1776 + } 1777 + 1778 + static unsigned short snd_riptide_codec_read(struct snd_ac97 *ac97, 1779 + unsigned short reg) 1780 + { 1781 + struct snd_riptide *chip = ac97->private_data; 1782 + struct cmdif *cif = chip->cif; 1783 + union cmdret rptr = CMDRET_ZERO; 1784 + 1785 + snd_assert(cif, return 0); 1786 + 1787 + if (SEND_RACR(cif, reg, &rptr) != 0) 1788 + SEND_RACR(cif, reg, &rptr); 1789 + snd_printdd("Read AC97 reg 0x%x got 0x%x\n", reg, rptr.retwords[1]); 1790 + return rptr.retwords[1]; 1791 + } 1792 + 1793 + static int snd_riptide_initialize(struct snd_riptide *chip) 1794 + { 1795 + struct cmdif *cif; 1796 + unsigned int device_id; 1797 + int err; 1798 + 1799 + snd_assert(chip, return -EINVAL); 1800 + 1801 + cif = chip->cif; 1802 + if (!cif) { 1803 + if ((cif = kzalloc(sizeof(struct cmdif), GFP_KERNEL)) == NULL) 1804 + return -ENOMEM; 1805 + cif->hwport = (struct riptideport *)chip->port; 1806 + spin_lock_init(&cif->lock); 1807 + chip->cif = cif; 1808 + } 1809 + cif->is_reset = 0; 1810 + if ((err = riptide_reset(cif, chip)) != 0) 1811 + return err; 1812 + device_id = chip->device_id; 1813 + switch (device_id) { 1814 + case 0x4310: 1815 + case 0x4320: 1816 + case 0x4330: 1817 + snd_printdd("Modem enable?\n"); 1818 + SEND_SETDPLL(cif); 1819 + break; 1820 + } 1821 + snd_printdd("Enabling MPU IRQs\n"); 1822 + if (chip->rmidi) 1823 + SET_EMPUIRQ(cif->hwport); 1824 + return err; 1825 + } 1826 + 1827 + static int snd_riptide_free(struct snd_riptide *chip) 1828 + { 1829 + struct cmdif *cif; 1830 + 1831 + snd_assert(chip, return 0); 1832 + 1833 + if ((cif = chip->cif)) { 1834 + SET_GRESET(cif->hwport); 1835 + udelay(100); 1836 + UNSET_GRESET(cif->hwport); 1837 + kfree(chip->cif); 1838 + } 1839 + if (chip->fw_entry) 1840 + release_firmware(chip->fw_entry); 1841 + release_and_free_resource(chip->res_port); 1842 + if (chip->irq >= 0) 1843 + free_irq(chip->irq, chip); 1844 + kfree(chip); 1845 + return 0; 1846 + } 1847 + 1848 + static int snd_riptide_dev_free(struct snd_device *device) 1849 + { 1850 + struct snd_riptide *chip = device->device_data; 1851 + 1852 + return snd_riptide_free(chip); 1853 + } 1854 + 1855 + static int __devinit 1856 + snd_riptide_create(struct snd_card *card, struct pci_dev *pci, 1857 + struct snd_riptide **rchip) 1858 + { 1859 + struct snd_riptide *chip; 1860 + struct riptideport *hwport; 1861 + int err; 1862 + static struct snd_device_ops ops = { 1863 + .dev_free = snd_riptide_dev_free, 1864 + }; 1865 + 1866 + *rchip = NULL; 1867 + if ((err = pci_enable_device(pci)) < 0) 1868 + return err; 1869 + if (!(chip = kzalloc(sizeof(struct snd_riptide), GFP_KERNEL))) 1870 + return -ENOMEM; 1871 + 1872 + spin_lock_init(&chip->lock); 1873 + chip->card = card; 1874 + chip->pci = pci; 1875 + chip->irq = -1; 1876 + chip->openstreams = 0; 1877 + chip->port = pci_resource_start(pci, 0); 1878 + chip->received_irqs = 0; 1879 + chip->handled_irqs = 0; 1880 + chip->cif = NULL; 1881 + tasklet_init(&chip->riptide_tq, riptide_handleirq, (unsigned long)chip); 1882 + 1883 + if ((chip->res_port = 1884 + request_region(chip->port, 64, "RIPTIDE")) == NULL) { 1885 + snd_printk(KERN_ERR 1886 + "Riptide: unable to grab region 0x%lx-0x%lx\n", 1887 + chip->port, chip->port + 64 - 1); 1888 + snd_riptide_free(chip); 1889 + return -EBUSY; 1890 + } 1891 + hwport = (struct riptideport *)chip->port; 1892 + UNSET_AIE(hwport); 1893 + 1894 + if (request_irq 1895 + (pci->irq, snd_riptide_interrupt, SA_INTERRUPT | SA_SHIRQ, 1896 + "RIPTIDE", chip)) { 1897 + snd_printk(KERN_ERR "Riptide: unable to grab IRQ %d\n", 1898 + pci->irq); 1899 + snd_riptide_free(chip); 1900 + return -EBUSY; 1901 + } 1902 + chip->irq = pci->irq; 1903 + chip->device_id = pci->device; 1904 + pci_set_master(pci); 1905 + if ((err = snd_riptide_initialize(chip)) < 0) { 1906 + snd_riptide_free(chip); 1907 + return err; 1908 + } 1909 + 1910 + if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1911 + snd_riptide_free(chip); 1912 + return err; 1913 + } 1914 + 1915 + *rchip = chip; 1916 + return 0; 1917 + } 1918 + 1919 + static void 1920 + snd_riptide_proc_read(struct snd_info_entry *entry, 1921 + struct snd_info_buffer *buffer) 1922 + { 1923 + struct snd_riptide *chip = entry->private_data; 1924 + struct pcmhw *data; 1925 + int i; 1926 + struct cmdif *cif = NULL; 1927 + unsigned char p[256]; 1928 + unsigned short rval = 0, lval = 0; 1929 + unsigned int rate; 1930 + 1931 + if (!chip) 1932 + return; 1933 + 1934 + snd_iprintf(buffer, "%s\n\n", chip->card->longname); 1935 + snd_iprintf(buffer, "Device ID: 0x%x\nReceived IRQs: (%ld)%ld\nPorts:", 1936 + chip->device_id, chip->handled_irqs, chip->received_irqs); 1937 + for (i = 0; i < 64; i += 4) 1938 + snd_iprintf(buffer, "%c%02x: %08x", 1939 + (i % 16) ? ' ' : '\n', i, inl(chip->port + i)); 1940 + if ((cif = chip->cif)) { 1941 + snd_iprintf(buffer, 1942 + "\nVersion: ASIC: %d CODEC: %d AUXDSP: %d PROG: %d", 1943 + chip->firmware.firmware.ASIC, 1944 + chip->firmware.firmware.CODEC, 1945 + chip->firmware.firmware.AUXDSP, 1946 + chip->firmware.firmware.PROG); 1947 + snd_iprintf(buffer, "\nDigital mixer:"); 1948 + for (i = 0; i < 12; i++) { 1949 + getmixer(cif, i, &rval, &lval); 1950 + snd_iprintf(buffer, "\n %d: %d %d", i, rval, lval); 1951 + } 1952 + snd_iprintf(buffer, 1953 + "\nARM Commands num: %d failed: %d time: %d max: %d min: %d", 1954 + cif->cmdcnt, cif->errcnt, 1955 + cif->cmdtime, cif->cmdtimemax, cif->cmdtimemin); 1956 + } 1957 + snd_iprintf(buffer, "\nOpen streams %d:\n", chip->openstreams); 1958 + for (i = 0; i < PLAYBACK_SUBSTREAMS; i++) { 1959 + if (chip->playback_substream[i] 1960 + && chip->playback_substream[i]->runtime 1961 + && (data = 1962 + chip->playback_substream[i]->runtime->private_data)) { 1963 + snd_iprintf(buffer, 1964 + "stream: %d mixer: %d source: %d (%d,%d)\n", 1965 + data->id, data->mixer, data->source, 1966 + data->intdec[0], data->intdec[1]); 1967 + if (!(getsamplerate(cif, data->intdec, &rate))) 1968 + snd_iprintf(buffer, "rate: %d\n", rate); 1969 + } 1970 + } 1971 + if (chip->capture_substream 1972 + && chip->capture_substream->runtime 1973 + && (data = chip->capture_substream->runtime->private_data)) { 1974 + snd_iprintf(buffer, 1975 + "stream: %d mixer: %d source: %d (%d,%d)\n", 1976 + data->id, data->mixer, 1977 + data->source, data->intdec[0], data->intdec[1]); 1978 + if (!(getsamplerate(cif, data->intdec, &rate))) 1979 + snd_iprintf(buffer, "rate: %d\n", rate); 1980 + } 1981 + snd_iprintf(buffer, "Paths:\n"); 1982 + i = getpaths(cif, p); 1983 + while (i--) { 1984 + snd_iprintf(buffer, "%x->%x ", p[i - 1], p[i]); 1985 + i--; 1986 + } 1987 + snd_iprintf(buffer, "\n"); 1988 + } 1989 + 1990 + static void __devinit snd_riptide_proc_init(struct snd_riptide *chip) 1991 + { 1992 + struct snd_info_entry *entry; 1993 + 1994 + if (!snd_card_proc_new(chip->card, "riptide", &entry)) 1995 + snd_info_set_text_ops(entry, chip, 4096, snd_riptide_proc_read); 1996 + } 1997 + 1998 + static int __devinit snd_riptide_mixer(struct snd_riptide *chip) 1999 + { 2000 + struct snd_ac97_bus *pbus; 2001 + struct snd_ac97_template ac97; 2002 + int err = 0; 2003 + static struct snd_ac97_bus_ops ops = { 2004 + .write = snd_riptide_codec_write, 2005 + .read = snd_riptide_codec_read, 2006 + }; 2007 + 2008 + memset(&ac97, 0, sizeof(ac97)); 2009 + ac97.private_data = chip; 2010 + ac97.scaps = AC97_SCAP_SKIP_MODEM; 2011 + 2012 + if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0) 2013 + return err; 2014 + 2015 + chip->ac97_bus = pbus; 2016 + ac97.pci = chip->pci; 2017 + if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97)) < 0) 2018 + return err; 2019 + return err; 2020 + } 2021 + 2022 + #ifdef SUPPORT_JOYSTICK 2023 + static int have_joystick; 2024 + static struct pci_dev *riptide_gameport_pci; 2025 + static struct gameport *riptide_gameport; 2026 + 2027 + static int __devinit 2028 + snd_riptide_joystick_probe(struct pci_dev *pci, const struct pci_device_id *id) 2029 + { 2030 + static int dev; 2031 + 2032 + if (dev >= SNDRV_CARDS) 2033 + return -ENODEV; 2034 + if (!enable[dev]) { 2035 + dev++; 2036 + return -ENOENT; 2037 + } 2038 + 2039 + if (joystick_port[dev]) { 2040 + riptide_gameport = gameport_allocate_port(); 2041 + if (riptide_gameport) { 2042 + if (!request_region 2043 + (joystick_port[dev], 8, "Riptide gameport")) { 2044 + snd_printk(KERN_WARNING 2045 + "Riptide: cannot grab gameport 0x%x\n", 2046 + joystick_port[dev]); 2047 + gameport_free_port(riptide_gameport); 2048 + riptide_gameport = NULL; 2049 + } else { 2050 + riptide_gameport_pci = pci; 2051 + riptide_gameport->io = joystick_port[dev]; 2052 + gameport_register_port(riptide_gameport); 2053 + } 2054 + } 2055 + } 2056 + dev++; 2057 + return 0; 2058 + } 2059 + 2060 + static void __devexit snd_riptide_joystick_remove(struct pci_dev *pci) 2061 + { 2062 + if (riptide_gameport) { 2063 + if (riptide_gameport_pci == pci) { 2064 + release_region(riptide_gameport->io, 8); 2065 + riptide_gameport_pci = NULL; 2066 + gameport_unregister_port(riptide_gameport); 2067 + riptide_gameport = NULL; 2068 + } 2069 + } 2070 + } 2071 + #endif 2072 + 2073 + static int __devinit 2074 + snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) 2075 + { 2076 + static int dev; 2077 + struct snd_card *card; 2078 + struct snd_riptide *chip; 2079 + unsigned short addr; 2080 + int err = 0; 2081 + 2082 + if (dev >= SNDRV_CARDS) 2083 + return -ENODEV; 2084 + if (!enable[dev]) { 2085 + dev++; 2086 + return -ENOENT; 2087 + } 2088 + 2089 + card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2090 + if (card == NULL) 2091 + return -ENOMEM; 2092 + if ((err = snd_riptide_create(card, pci, &chip)) < 0) { 2093 + snd_card_free(card); 2094 + return err; 2095 + } 2096 + card->private_data = chip; 2097 + if ((err = snd_riptide_pcm(chip, 0, NULL)) < 0) { 2098 + snd_card_free(card); 2099 + return err; 2100 + } 2101 + if ((err = snd_riptide_mixer(chip)) < 0) { 2102 + snd_card_free(card); 2103 + return err; 2104 + } 2105 + pci_write_config_word(chip->pci, PCI_EXT_Legacy_Mask, LEGACY_ENABLE_ALL 2106 + | (opl3_port[dev] ? LEGACY_ENABLE_FM : 0) 2107 + #ifdef SUPPORT_JOYSTICK 2108 + | (joystick_port[dev] ? LEGACY_ENABLE_GAMEPORT : 2109 + 0) 2110 + #endif 2111 + | (mpu_port[dev] 2112 + ? (LEGACY_ENABLE_MPU_INT | LEGACY_ENABLE_MPU) : 2113 + 0) 2114 + | ((chip->irq << 4) & 0xF0)); 2115 + if ((addr = mpu_port[dev]) != 0) { 2116 + pci_write_config_word(chip->pci, PCI_EXT_MPU_Base, addr); 2117 + if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_RIPTIDE, 2118 + addr, 0, chip->irq, 0, 2119 + &chip->rmidi)) < 0) 2120 + snd_printk(KERN_WARNING 2121 + "Riptide: Can't Allocate MPU at 0x%x\n", 2122 + addr); 2123 + else 2124 + chip->mpuaddr = addr; 2125 + } 2126 + if ((addr = opl3_port[dev]) != 0) { 2127 + pci_write_config_word(chip->pci, PCI_EXT_FM_Base, addr); 2128 + if ((err = snd_opl3_create(card, addr, addr + 2, 2129 + OPL3_HW_RIPTIDE, 0, 2130 + &chip->opl3)) < 0) 2131 + snd_printk(KERN_WARNING 2132 + "Riptide: Can't Allocate OPL3 at 0x%x\n", 2133 + addr); 2134 + else { 2135 + chip->opladdr = addr; 2136 + if ((err = 2137 + snd_opl3_hwdep_new(chip->opl3, 0, 1, NULL)) < 0) 2138 + snd_printk(KERN_WARNING 2139 + "Riptide: Can't Allocate OPL3-HWDEP\n"); 2140 + } 2141 + } 2142 + #ifdef SUPPORT_JOYSTICK 2143 + if ((addr = joystick_port[dev]) != 0) { 2144 + pci_write_config_word(chip->pci, PCI_EXT_Game_Base, addr); 2145 + chip->gameaddr = addr; 2146 + } 2147 + #endif 2148 + 2149 + strcpy(card->driver, "RIPTIDE"); 2150 + strcpy(card->shortname, "Riptide"); 2151 + #ifdef SUPPORT_JOYSTICK 2152 + snprintf(card->longname, sizeof(card->longname), 2153 + "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x gameport 0x%x", 2154 + card->shortname, chip->port, chip->irq, chip->mpuaddr, 2155 + chip->opladdr, chip->gameaddr); 2156 + #else 2157 + snprintf(card->longname, sizeof(card->longname), 2158 + "%s at 0x%lx, irq %i mpu 0x%x opl3 0x%x", 2159 + card->shortname, chip->port, chip->irq, chip->mpuaddr, 2160 + chip->opladdr); 2161 + #endif 2162 + snd_riptide_proc_init(chip); 2163 + if ((err = snd_card_register(card)) < 0) { 2164 + snd_card_free(card); 2165 + return err; 2166 + } 2167 + pci_set_drvdata(pci, card); 2168 + dev++; 2169 + return 0; 2170 + } 2171 + 2172 + static void __devexit snd_card_riptide_remove(struct pci_dev *pci) 2173 + { 2174 + snd_card_free(pci_get_drvdata(pci)); 2175 + pci_set_drvdata(pci, NULL); 2176 + } 2177 + 2178 + static struct pci_driver driver = { 2179 + .name = "RIPTIDE", 2180 + .id_table = snd_riptide_ids, 2181 + .probe = snd_card_riptide_probe, 2182 + .remove = __devexit_p(snd_card_riptide_remove), 2183 + #ifdef CONFIG_PM 2184 + .suspend = riptide_suspend, 2185 + .resume = riptide_resume, 2186 + #endif 2187 + }; 2188 + 2189 + #ifdef SUPPORT_JOYSTICK 2190 + static struct pci_driver joystick_driver = { 2191 + .name = "Riptide Joystick", 2192 + .id_table = snd_riptide_joystick_ids, 2193 + .probe = snd_riptide_joystick_probe, 2194 + .remove = __devexit_p(snd_riptide_joystick_remove), 2195 + }; 2196 + #endif 2197 + 2198 + static int __init alsa_card_riptide_init(void) 2199 + { 2200 + int err; 2201 + if ((err = pci_register_driver(&driver)) < 0) 2202 + return err; 2203 + #if defined(SUPPORT_JOYSTICK) 2204 + if (pci_register_driver(&joystick_driver) < 0) { 2205 + have_joystick = 0; 2206 + snd_printk(KERN_INFO "no joystick found\n"); 2207 + } else 2208 + have_joystick = 1; 2209 + #endif 2210 + return 0; 2211 + } 2212 + 2213 + static void __exit alsa_card_riptide_exit(void) 2214 + { 2215 + pci_unregister_driver(&driver); 2216 + #if defined(SUPPORT_JOYSTICK) 2217 + if (have_joystick) 2218 + pci_unregister_driver(&joystick_driver); 2219 + #endif 2220 + } 2221 + 2222 + module_init(alsa_card_riptide_init); 2223 + module_exit(alsa_card_riptide_exit);
+1
sound/pci/via82xx.c
··· 2373 { .subvendor = 0x161f, .subdevice = 0x2032, .action = VIA_DXS_48K }, /* m680x machines */ 2374 { .subvendor = 0x1631, .subdevice = 0xe004, .action = VIA_DXS_ENABLE }, /* Easy Note 3174, Packard Bell */ 2375 { .subvendor = 0x1695, .subdevice = 0x3005, .action = VIA_DXS_ENABLE }, /* EPoX EP-8K9A */ 2376 { .subvendor = 0x1695, .subdevice = 0x300e, .action = VIA_DXS_SRC }, /* EPoX 9HEAI */ 2377 { .subvendor = 0x16f3, .subdevice = 0x6405, .action = VIA_DXS_SRC }, /* Jetway K8M8MS */ 2378 { .subvendor = 0x1734, .subdevice = 0x1078, .action = VIA_DXS_SRC }, /* FSC Amilo L7300 */
··· 2373 { .subvendor = 0x161f, .subdevice = 0x2032, .action = VIA_DXS_48K }, /* m680x machines */ 2374 { .subvendor = 0x1631, .subdevice = 0xe004, .action = VIA_DXS_ENABLE }, /* Easy Note 3174, Packard Bell */ 2375 { .subvendor = 0x1695, .subdevice = 0x3005, .action = VIA_DXS_ENABLE }, /* EPoX EP-8K9A */ 2376 + { .subvendor = 0x1695, .subdevice = 0x300c, .action = VIA_DXS_SRC }, /* EPoX EP-8KRAI */ 2377 { .subvendor = 0x1695, .subdevice = 0x300e, .action = VIA_DXS_SRC }, /* EPoX 9HEAI */ 2378 { .subvendor = 0x16f3, .subdevice = 0x6405, .action = VIA_DXS_SRC }, /* Jetway K8M8MS */ 2379 { .subvendor = 0x1734, .subdevice = 0x1078, .action = VIA_DXS_SRC }, /* FSC Amilo L7300 */
+34 -3
sound/usb/usbmixer.c
··· 306 cval->res = 1; 307 if (val < cval->min) 308 return 0; 309 - else if (val > cval->max) 310 - return (cval->max - cval->min) / cval->res; 311 else 312 return (val - cval->min) / cval->res; 313 } ··· 670 } 671 if (cval->res == 0) 672 cval->res = 1; 673 cval->initialized = 1; 674 } 675 return 0; ··· 725 if (! cval->initialized) 726 get_min_max(cval, 0); 727 uinfo->value.integer.min = 0; 728 - uinfo->value.integer.max = (cval->max - cval->min) / cval->res; 729 } 730 return 0; 731 }
··· 306 cval->res = 1; 307 if (val < cval->min) 308 return 0; 309 + else if (val >= cval->max) 310 + return (cval->max - cval->min + cval->res - 1) / cval->res; 311 else 312 return (val - cval->min) / cval->res; 313 } ··· 670 } 671 if (cval->res == 0) 672 cval->res = 1; 673 + 674 + /* Additional checks for the proper resolution 675 + * 676 + * Some devices report smaller resolutions than actually 677 + * reacting. They don't return errors but simply clip 678 + * to the lower aligned value. 679 + */ 680 + if (cval->min + cval->res < cval->max) { 681 + int last_valid_res = cval->res; 682 + int saved, test, check; 683 + get_cur_mix_value(cval, minchn, &saved); 684 + for (;;) { 685 + test = saved; 686 + if (test < cval->max) 687 + test += cval->res; 688 + else 689 + test -= cval->res; 690 + if (test < cval->min || test > cval->max || 691 + set_cur_mix_value(cval, minchn, test) || 692 + get_cur_mix_value(cval, minchn, &check)) { 693 + cval->res = last_valid_res; 694 + break; 695 + } 696 + if (test == check) 697 + break; 698 + cval->res *= 2; 699 + } 700 + set_cur_mix_value(cval, minchn, saved); 701 + } 702 + 703 cval->initialized = 1; 704 } 705 return 0; ··· 695 if (! cval->initialized) 696 get_min_max(cval, 0); 697 uinfo->value.integer.min = 0; 698 + uinfo->value.integer.max = 699 + (cval->max - cval->min + cval->res - 1) / cval->res; 700 } 701 return 0; 702 }