Changeset 305 for GPL/branches/uniaud-2.0/alsa-kernel/pci/sonicvibes.c
- Timestamp:
- Mar 24, 2008, 2:43:42 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/branches/uniaud-2.0/alsa-kernel/pci/sonicvibes.c
r77 r305 1 1 /* 2 2 * Driver for S3 SonicVibes soundcard 3 * Copyright (c) by Jaroslav Kysela <perex@ suse.cz>3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 4 4 * 5 5 * BUGS: … … 19 19 * You should have received a copy of the GNU General Public License 20 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 22 * 23 23 */ 24 24 25 #define SNDRV_MAIN_OBJECT_FILE 26 #include <sound/driver.h> 25 #include <linux/delay.h> 26 #include <linux/init.h> 27 #include <linux/interrupt.h> 28 #include <linux/pci.h> 29 #include <linux/slab.h> 30 #include <linux/gameport.h> 31 #include <linux/moduleparam.h> 32 #include <linux/dma-mapping.h> 33 34 #include <sound/core.h> 27 35 #include <sound/pcm.h> 28 36 #include <sound/info.h> … … 30 38 #include <sound/mpu401.h> 31 39 #include <sound/opl3.h> 32 #define SNDRV_GET_ID33 40 #include <sound/initval.h> 34 41 35 EXPORT_NO_SYMBOLS; 42 #include <asm/io.h> 43 44 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 36 45 MODULE_DESCRIPTION("S3 SonicVibes PCI"); 37 MODULE_ CLASSES("{sound}");38 MODULE_ DEVICES("{{S3,SonicVibes PCI}}");39 40 #if ndef PCI_VENDOR_ID_S341 #define PCI_VENDOR_ID_S3 0x533346 MODULE_LICENSE("GPL"); 47 MODULE_SUPPORTED_DEVICE("{{S3,SonicVibes PCI}}"); 48 49 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) 50 #define SUPPORT_JOYSTICK 1 42 51 #endif 43 #ifndef PCI_DEVICE_ID_S3_SONICVIBES 44 #define PCI_DEVICE_ID_S3_SONICVIBES 0xca00 45 #endif 46 47 static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 48 static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 49 static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ 50 #ifdef TARGET_OS2 51 static int snd_reverb[SNDRV_CARDS] = {0,0,0,0,0,0,0,0}; 52 static int snd_mge[SNDRV_CARDS] = {0,0,0,0,0,0,0,0}; 53 #else 54 static int snd_reverb[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; 55 static int snd_mge[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; 56 #endif 57 static unsigned int snd_dmaio = 0x7a00; /* DDMA i/o address */ 58 59 MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); 60 MODULE_PARM_DESC(snd_index, "Index value for S3 SonicVibes soundcard."); 61 MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC); 62 MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s"); 63 MODULE_PARM_DESC(snd_id, "ID string for S3 SonicVibes soundcard."); 64 MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC); 65 MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); 66 MODULE_PARM_DESC(snd_enable, "Enable S3 SonicVibes soundcard."); 67 MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC); 68 MODULE_PARM(snd_reverb, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); 69 MODULE_PARM_DESC(snd_reverb, "Enable reverb (SRAM is present) for S3 SonicVibes soundcard."); 70 MODULE_PARM_SYNTAX(snd_reverb, SNDRV_ENABLED "," SNDRV_ENABLE_DESC); 71 MODULE_PARM(snd_mge, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); 72 MODULE_PARM_DESC(snd_mge, "MIC Gain Enable for S3 SonicVibes soundcard."); 73 MODULE_PARM_SYNTAX(snd_mge, SNDRV_ENABLED "," SNDRV_ENABLE_DESC); 74 MODULE_PARM(snd_dmaio, "i"); 75 MODULE_PARM_DESC(snd_dmaio, "DDMA i/o base address for S3 SonicVibes soundcard."); 76 MODULE_PARM_SYNTAX(snd_dmaio, "global," SNDRV_PORT_DESC); 52 53 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 54 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 55 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 56 static int reverb[SNDRV_CARDS]; 57 static int mge[SNDRV_CARDS]; 58 static unsigned int dmaio = 0x7a00; /* DDMA i/o address */ 59 60 module_param_array(index, int, NULL, 0444); 61 MODULE_PARM_DESC(index, "Index value for S3 SonicVibes soundcard."); 62 module_param_array(id, charp, NULL, 0444); 63 MODULE_PARM_DESC(id, "ID string for S3 SonicVibes soundcard."); 64 module_param_array(enable, bool, NULL, 0444); 65 MODULE_PARM_DESC(enable, "Enable S3 SonicVibes soundcard."); 66 module_param_array(reverb, bool, NULL, 0444); 67 MODULE_PARM_DESC(reverb, "Enable reverb (SRAM is present) for S3 SonicVibes soundcard."); 68 module_param_array(mge, bool, NULL, 0444); 69 MODULE_PARM_DESC(mge, "MIC Gain Enable for S3 SonicVibes soundcard."); 70 module_param(dmaio, uint, 0444); 71 MODULE_PARM_DESC(dmaio, "DDMA i/o base address for S3 SonicVibes soundcard."); 77 72 78 73 /* … … 201 196 */ 202 197 203 typedef struct _snd_sonicvibes sonicvibes_t; 204 #define chip_t sonicvibes_t 205 206 struct _snd_sonicvibes { 198 struct sonicvibes { 207 199 unsigned long dma1size; 208 200 unsigned long dma2size; … … 210 202 211 203 unsigned long sb_port; 212 struct resource *res_sb_port;213 204 unsigned long enh_port; 214 struct resource *res_enh_port;215 205 unsigned long synth_port; 216 struct resource *res_synth_port;217 206 unsigned long midi_port; 218 struct resource *res_midi_port;219 207 unsigned long game_port; 220 208 unsigned int dmaa_port; … … 235 223 236 224 struct pci_dev *pci; 237 s nd_card_t*card;238 s nd_pcm_t*pcm;239 s nd_pcm_substream_t*playback_substream;240 s nd_pcm_substream_t*capture_substream;241 s nd_rawmidi_t*rmidi;242 s nd_hwdep_t*fmsynth; /* S3FM */225 struct snd_card *card; 226 struct snd_pcm *pcm; 227 struct snd_pcm_substream *playback_substream; 228 struct snd_pcm_substream *capture_substream; 229 struct snd_rawmidi *rmidi; 230 struct snd_hwdep *fmsynth; /* S3FM */ 243 231 244 232 spinlock_t reg_lock; 245 snd_info_entry_t *proc_entry;246 233 247 234 unsigned int p_dma_size; 248 235 unsigned int c_dma_size; 249 236 250 snd_kcontrol_t *master_mute; 251 snd_kcontrol_t *master_volume; 237 struct snd_kcontrol *master_mute; 238 struct snd_kcontrol *master_volume; 239 240 #ifdef SUPPORT_JOYSTICK 241 struct gameport *gameport; 242 #endif 252 243 }; 253 244 254 static struct pci_device_id snd_sonic_ids[] __devinitdata= {245 static struct pci_device_id snd_sonic_ids[] = { 255 246 { 0x5333, 0xca00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 256 247 { 0, } … … 259 250 MODULE_DEVICE_TABLE(pci, snd_sonic_ids); 260 251 261 #ifdef TARGET_OS2 262 static ratden_t sonicvibes_adc_clock = { 263 4000 * 65536, 264 48000UL * 65536, 265 1, 266 65536, 252 static struct snd_ratden sonicvibes_adc_clock = { 253 .num_min = 4000 * 65536, 254 .num_max = 48000UL * 65536, 255 .num_step = 1, 256 .den = 65536, 267 257 }; 268 static s nd_pcm_hw_constraint_ratdens_tsnd_sonicvibes_hw_constraints_adc_clock = {269 1,270 &sonicvibes_adc_clock,258 static struct snd_pcm_hw_constraint_ratdens snd_sonicvibes_hw_constraints_adc_clock = { 259 .nrats = 1, 260 .rats = &sonicvibes_adc_clock, 271 261 }; 272 #else273 static ratden_t sonicvibes_adc_clock = {274 num_min: 4000 * 65536,275 num_max: 48000UL * 65536,276 num_step: 1,277 den: 65536,278 };279 static snd_pcm_hw_constraint_ratdens_t snd_sonicvibes_hw_constraints_adc_clock = {280 nrats: 1,281 rats: &sonicvibes_adc_clock,282 };283 #endif284 262 285 263 /* … … 287 265 */ 288 266 289 static inline void snd_sonicvibes_setdmaa(s onicvibes_t* sonic,267 static inline void snd_sonicvibes_setdmaa(struct sonicvibes * sonic, 290 268 unsigned int addr, 291 269 unsigned int count) … … 300 278 } 301 279 302 static inline void snd_sonicvibes_setdmac(s onicvibes_t* sonic,280 static inline void snd_sonicvibes_setdmac(struct sonicvibes * sonic, 303 281 unsigned int addr, 304 282 unsigned int count) … … 315 293 } 316 294 317 static inline unsigned int snd_sonicvibes_getdmaa(s onicvibes_t* sonic)295 static inline unsigned int snd_sonicvibes_getdmaa(struct sonicvibes * sonic) 318 296 { 319 297 return (inl(sonic->dmaa_port + SV_DMA_COUNT0) & 0xffffff) + 1; 320 298 } 321 299 322 static inline unsigned int snd_sonicvibes_getdmac(s onicvibes_t* sonic)300 static inline unsigned int snd_sonicvibes_getdmac(struct sonicvibes * sonic) 323 301 { 324 302 /* note: dmac is working in word mode!!! */ … … 326 304 } 327 305 328 static void snd_sonicvibes_out1(s onicvibes_t* sonic,306 static void snd_sonicvibes_out1(struct sonicvibes * sonic, 329 307 unsigned char reg, 330 308 unsigned char value) … … 336 314 } 337 315 338 static void snd_sonicvibes_out(s onicvibes_t* sonic,316 static void snd_sonicvibes_out(struct sonicvibes * sonic, 339 317 unsigned char reg, 340 318 unsigned char value) … … 350 328 } 351 329 352 static unsigned char snd_sonicvibes_in1(s onicvibes_t* sonic, unsigned char reg)330 static unsigned char snd_sonicvibes_in1(struct sonicvibes * sonic, unsigned char reg) 353 331 { 354 332 unsigned char value; … … 361 339 } 362 340 363 static unsigned char snd_sonicvibes_in(s onicvibes_t* sonic, unsigned char reg)341 static unsigned char snd_sonicvibes_in(struct sonicvibes * sonic, unsigned char reg) 364 342 { 365 343 unsigned long flags; … … 375 353 } 376 354 377 #if def CONFIG_SND_DEBUG378 void snd_sonicvibes_debug(sonicvibes_t* sonic)355 #if 0 356 static void snd_sonicvibes_debug(struct sonicvibes * sonic) 379 357 { 380 358 printk("SV REGS: INDEX = 0x%02x ", inb(SV_REG(sonic, INDEX))); … … 448 426 #endif 449 427 450 static void snd_sonicvibes_setfmt(s onicvibes_t* sonic,428 static void snd_sonicvibes_setfmt(struct sonicvibes * sonic, 451 429 unsigned char mask, 452 430 unsigned char value) … … 504 482 } 505 483 506 static void snd_sonicvibes_setpll(s onicvibes_t* sonic,484 static void snd_sonicvibes_setpll(struct sonicvibes * sonic, 507 485 unsigned char reg, 508 486 unsigned int rate) … … 520 498 } 521 499 522 static void snd_sonicvibes_set_adc_rate(s onicvibes_t* sonic, unsigned int rate)500 static void snd_sonicvibes_set_adc_rate(struct sonicvibes * sonic, unsigned int rate) 523 501 { 524 502 unsigned long flags; … … 541 519 } 542 520 543 static int snd_sonicvibes_hw_constraint_dac_rate(s nd_pcm_hw_params_t*params,544 s nd_pcm_hw_rule_t*rule)521 static int snd_sonicvibes_hw_constraint_dac_rate(struct snd_pcm_hw_params *params, 522 struct snd_pcm_hw_rule *rule) 545 523 { 546 524 unsigned int rate, div, r, m, n; … … 566 544 } 567 545 568 static void snd_sonicvibes_set_dac_rate(s onicvibes_t* sonic, unsigned int rate)546 static void snd_sonicvibes_set_dac_rate(struct sonicvibes * sonic, unsigned int rate) 569 547 { 570 548 unsigned int div; … … 580 558 } 581 559 582 static int snd_sonicvibes_trigger(s onicvibes_t* sonic, int what, int cmd)560 static int snd_sonicvibes_trigger(struct sonicvibes * sonic, int what, int cmd) 583 561 { 584 562 int result = 0; … … 602 580 } 603 581 604 static void snd_sonicvibes_interrupt(int irq, void *dev_id, struct pt_regs *regs)605 { 606 s onicvibes_t *sonic = snd_magic_cast(sonicvibes_t, dev_id, return);582 static irqreturn_t snd_sonicvibes_interrupt(int irq, void *dev_id) 583 { 584 struct sonicvibes *sonic = dev_id; 607 585 unsigned char status; 608 586 609 587 status = inb(SV_REG(sonic, STATUS)); 610 588 if (!(status & (SV_DMAA_IRQ | SV_DMAC_IRQ | SV_MIDI_IRQ))) 611 return ;589 return IRQ_NONE; 612 590 if (status == 0xff) { /* failure */ 613 591 outb(sonic->irqmask = ~0, SV_REG(sonic, IRQMASK)); 614 snd_printk( "IRQ failure - interrupts disabled!!\n");615 return ;592 snd_printk(KERN_ERR "IRQ failure - interrupts disabled!!\n"); 593 return IRQ_HANDLED; 616 594 } 617 595 if (sonic->pcm) { … … 623 601 if (sonic->rmidi) { 624 602 if (status & SV_MIDI_IRQ) 625 snd_mpu401_uart_interrupt(irq, sonic->rmidi->private_data , regs);603 snd_mpu401_uart_interrupt(irq, sonic->rmidi->private_data); 626 604 } 627 605 if (status & SV_UD_IRQ) { … … 660 638 snd_ctl_notify(sonic->card, SNDRV_CTL_EVENT_MASK_VALUE, &sonic->master_volume->id); 661 639 } 640 return IRQ_HANDLED; 662 641 } 663 642 … … 666 645 */ 667 646 668 static int snd_sonicvibes_playback_trigger(s nd_pcm_substream_t *substream,647 static int snd_sonicvibes_playback_trigger(struct snd_pcm_substream *substream, 669 648 int cmd) 670 649 { 671 s onicvibes_t*sonic = snd_pcm_substream_chip(substream);650 struct sonicvibes *sonic = snd_pcm_substream_chip(substream); 672 651 return snd_sonicvibes_trigger(sonic, 1, cmd); 673 652 } 674 653 675 static int snd_sonicvibes_capture_trigger(s nd_pcm_substream_t *substream,654 static int snd_sonicvibes_capture_trigger(struct snd_pcm_substream *substream, 676 655 int cmd) 677 656 { 678 s onicvibes_t*sonic = snd_pcm_substream_chip(substream);657 struct sonicvibes *sonic = snd_pcm_substream_chip(substream); 679 658 return snd_sonicvibes_trigger(sonic, 2, cmd); 680 659 } 681 660 682 static int snd_sonicvibes_hw_params(s nd_pcm_substream_t *substream,683 s nd_pcm_hw_params_t *hw_params)661 static int snd_sonicvibes_hw_params(struct snd_pcm_substream *substream, 662 struct snd_pcm_hw_params *hw_params) 684 663 { 685 664 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); 686 665 } 687 666 688 static int snd_sonicvibes_hw_free(s nd_pcm_substream_t *substream)667 static int snd_sonicvibes_hw_free(struct snd_pcm_substream *substream) 689 668 { 690 669 return snd_pcm_lib_free_pages(substream); 691 670 } 692 671 693 static int snd_sonicvibes_playback_prepare(snd_pcm_substream_t * substream) 694 { 695 unsigned long flags; 696 sonicvibes_t *sonic = snd_pcm_substream_chip(substream); 697 snd_pcm_runtime_t *runtime = substream->runtime; 672 static int snd_sonicvibes_playback_prepare(struct snd_pcm_substream *substream) 673 { 674 struct sonicvibes *sonic = snd_pcm_substream_chip(substream); 675 struct snd_pcm_runtime *runtime = substream->runtime; 698 676 unsigned char fmt = 0; 699 677 unsigned int size = snd_pcm_lib_buffer_bytes(substream); … … 708 686 snd_sonicvibes_setfmt(sonic, ~3, fmt); 709 687 snd_sonicvibes_set_dac_rate(sonic, runtime->rate); 710 spin_lock_irq save(&sonic->reg_lock, flags);688 spin_lock_irq(&sonic->reg_lock); 711 689 snd_sonicvibes_setdmaa(sonic, runtime->dma_addr, size); 712 690 snd_sonicvibes_out1(sonic, SV_IREG_DMA_A_UPPER, count >> 8); 713 691 snd_sonicvibes_out1(sonic, SV_IREG_DMA_A_LOWER, count); 714 spin_unlock_irqrestore(&sonic->reg_lock, flags); 715 return 0; 716 } 717 718 static int snd_sonicvibes_capture_prepare(snd_pcm_substream_t * substream) 719 { 720 unsigned long flags; 721 sonicvibes_t *sonic = snd_pcm_substream_chip(substream); 722 snd_pcm_runtime_t *runtime = substream->runtime; 692 spin_unlock_irq(&sonic->reg_lock); 693 return 0; 694 } 695 696 static int snd_sonicvibes_capture_prepare(struct snd_pcm_substream *substream) 697 { 698 struct sonicvibes *sonic = snd_pcm_substream_chip(substream); 699 struct snd_pcm_runtime *runtime = substream->runtime; 723 700 unsigned char fmt = 0; 724 701 unsigned int size = snd_pcm_lib_buffer_bytes(substream); … … 734 711 snd_sonicvibes_setfmt(sonic, ~0x30, fmt); 735 712 snd_sonicvibes_set_adc_rate(sonic, runtime->rate); 736 spin_lock_irq save(&sonic->reg_lock, flags);713 spin_lock_irq(&sonic->reg_lock); 737 714 snd_sonicvibes_setdmac(sonic, runtime->dma_addr, size); 738 715 snd_sonicvibes_out1(sonic, SV_IREG_DMA_C_UPPER, count >> 8); 739 716 snd_sonicvibes_out1(sonic, SV_IREG_DMA_C_LOWER, count); 740 spin_unlock_irq restore(&sonic->reg_lock, flags);741 return 0; 742 } 743 744 static snd_pcm_uframes_t snd_sonicvibes_playback_pointer(s nd_pcm_substream_t *substream)745 { 746 s onicvibes_t*sonic = snd_pcm_substream_chip(substream);717 spin_unlock_irq(&sonic->reg_lock); 718 return 0; 719 } 720 721 static snd_pcm_uframes_t snd_sonicvibes_playback_pointer(struct snd_pcm_substream *substream) 722 { 723 struct sonicvibes *sonic = snd_pcm_substream_chip(substream); 747 724 size_t ptr; 748 725 … … 753 730 } 754 731 755 static snd_pcm_uframes_t snd_sonicvibes_capture_pointer(s nd_pcm_substream_t *substream)756 { 757 s onicvibes_t*sonic = snd_pcm_substream_chip(substream);732 static snd_pcm_uframes_t snd_sonicvibes_capture_pointer(struct snd_pcm_substream *substream) 733 { 734 struct sonicvibes *sonic = snd_pcm_substream_chip(substream); 758 735 size_t ptr; 759 736 if (!(sonic->enable & 2)) … … 763 740 } 764 741 765 #ifdef TARGET_OS2 766 static snd_pcm_hardware_t snd_sonicvibes_playback = 767 { 768 /* info: */ (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 742 static struct snd_pcm_hardware snd_sonicvibes_playback = 743 { 744 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 769 745 SNDRV_PCM_INFO_BLOCK_TRANSFER | 770 746 SNDRV_PCM_INFO_MMAP_VALID), 771 /* formats: */SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,772 /* rates: */SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,773 /* rate_min: */4000,774 /* rate_max: */48000,775 /* channels_min: */1,776 /* channels_max: */2,777 /* buffer_bytes_max: */(128*1024),778 /* period_bytes_min: */32,779 /* period_bytes_max: */(128*1024),780 /* periods_min: */1,781 /* periods_max: */1024,782 /* fifo_size: */0,747 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 748 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, 749 .rate_min = 4000, 750 .rate_max = 48000, 751 .channels_min = 1, 752 .channels_max = 2, 753 .buffer_bytes_max = (128*1024), 754 .period_bytes_min = 32, 755 .period_bytes_max = (128*1024), 756 .periods_min = 1, 757 .periods_max = 1024, 758 .fifo_size = 0, 783 759 }; 784 760 785 static s nd_pcm_hardware_tsnd_sonicvibes_capture =786 { 787 /* info: */(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |761 static struct snd_pcm_hardware snd_sonicvibes_capture = 762 { 763 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 788 764 SNDRV_PCM_INFO_BLOCK_TRANSFER | 789 765 SNDRV_PCM_INFO_MMAP_VALID), 790 /* formats: */SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,791 /* rates: */SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,792 /* rate_min: */4000,793 /* rate_max: */48000,794 /* channels_min: */1,795 /* channels_max: */2,796 /* buffer_bytes_max: */(128*1024),797 /* period_bytes_min: */32,798 /* period_bytes_max: */(128*1024),799 /* periods_min: */1,800 /* periods_max: */1024,801 /* fifo_size: */0,766 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 767 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, 768 .rate_min = 4000, 769 .rate_max = 48000, 770 .channels_min = 1, 771 .channels_max = 2, 772 .buffer_bytes_max = (128*1024), 773 .period_bytes_min = 32, 774 .period_bytes_max = (128*1024), 775 .periods_min = 1, 776 .periods_max = 1024, 777 .fifo_size = 0, 802 778 }; 803 #else 804 static snd_pcm_hardware_t snd_sonicvibes_playback = 805 { 806 info: (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 807 SNDRV_PCM_INFO_BLOCK_TRANSFER | 808 SNDRV_PCM_INFO_MMAP_VALID), 809 formats: SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 810 rates: SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, 811 rate_min: 4000, 812 rate_max: 48000, 813 channels_min: 1, 814 channels_max: 2, 815 buffer_bytes_max: (128*1024), 816 period_bytes_min: 32, 817 period_bytes_max: (128*1024), 818 periods_min: 1, 819 periods_max: 1024, 820 fifo_size: 0, 821 }; 822 823 static snd_pcm_hardware_t snd_sonicvibes_capture = 824 { 825 info: (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 826 SNDRV_PCM_INFO_BLOCK_TRANSFER | 827 SNDRV_PCM_INFO_MMAP_VALID), 828 formats: SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, 829 rates: SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, 830 rate_min: 4000, 831 rate_max: 48000, 832 channels_min: 1, 833 channels_max: 2, 834 buffer_bytes_max: (128*1024), 835 period_bytes_min: 32, 836 period_bytes_max: (128*1024), 837 periods_min: 1, 838 periods_max: 1024, 839 fifo_size: 0, 840 }; 841 #endif 842 843 static int snd_sonicvibes_playback_open(snd_pcm_substream_t * substream) 844 { 845 sonicvibes_t *sonic = snd_pcm_substream_chip(substream); 846 snd_pcm_runtime_t *runtime = substream->runtime; 779 780 static int snd_sonicvibes_playback_open(struct snd_pcm_substream *substream) 781 { 782 struct sonicvibes *sonic = snd_pcm_substream_chip(substream); 783 struct snd_pcm_runtime *runtime = substream->runtime; 847 784 848 785 sonic->mode |= SV_MODE_PLAY; 849 786 sonic->playback_substream = substream; 850 787 runtime->hw = snd_sonicvibes_playback; 851 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_sonicvibes_hw_constraint_dac_rate, 0, SNDRV_PCM_HW_PARAM_RATE, -1);852 return 0; 853 } 854 855 static int snd_sonicvibes_capture_open(s nd_pcm_substream_t *substream)856 { 857 s onicvibes_t*sonic = snd_pcm_substream_chip(substream);858 s nd_pcm_runtime_t*runtime = substream->runtime;788 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_sonicvibes_hw_constraint_dac_rate, NULL, SNDRV_PCM_HW_PARAM_RATE, -1); 789 return 0; 790 } 791 792 static int snd_sonicvibes_capture_open(struct snd_pcm_substream *substream) 793 { 794 struct sonicvibes *sonic = snd_pcm_substream_chip(substream); 795 struct snd_pcm_runtime *runtime = substream->runtime; 859 796 860 797 sonic->mode |= SV_MODE_CAPTURE; … … 866 803 } 867 804 868 static int snd_sonicvibes_playback_close(s nd_pcm_substream_t *substream)869 { 870 s onicvibes_t*sonic = snd_pcm_substream_chip(substream);805 static int snd_sonicvibes_playback_close(struct snd_pcm_substream *substream) 806 { 807 struct sonicvibes *sonic = snd_pcm_substream_chip(substream); 871 808 872 809 sonic->playback_substream = NULL; … … 875 812 } 876 813 877 static int snd_sonicvibes_capture_close(s nd_pcm_substream_t *substream)878 { 879 s onicvibes_t*sonic = snd_pcm_substream_chip(substream);814 static int snd_sonicvibes_capture_close(struct snd_pcm_substream *substream) 815 { 816 struct sonicvibes *sonic = snd_pcm_substream_chip(substream); 880 817 881 818 sonic->capture_substream = NULL; … … 884 821 } 885 822 886 887 #ifdef TARGET_OS2 888 static snd_pcm_ops_t snd_sonicvibes_playback_ops = { 889 /* open: */ snd_sonicvibes_playback_open, 890 /* close: */ snd_sonicvibes_playback_close, 891 /* ioctl: */ snd_pcm_lib_ioctl, 892 /* hw_params:*/ snd_sonicvibes_hw_params, 893 /* hw_free: */ snd_sonicvibes_hw_free, 894 /* prepare: */ snd_sonicvibes_playback_prepare, 895 /* trigger: */ snd_sonicvibes_playback_trigger, 896 /* pointer: */ snd_sonicvibes_playback_pointer, 897 0, 0 823 static struct snd_pcm_ops snd_sonicvibes_playback_ops = { 824 .open = snd_sonicvibes_playback_open, 825 .close = snd_sonicvibes_playback_close, 826 .ioctl = snd_pcm_lib_ioctl, 827 .hw_params = snd_sonicvibes_hw_params, 828 .hw_free = snd_sonicvibes_hw_free, 829 .prepare = snd_sonicvibes_playback_prepare, 830 .trigger = snd_sonicvibes_playback_trigger, 831 .pointer = snd_sonicvibes_playback_pointer, 898 832 }; 899 833 900 static snd_pcm_ops_t snd_sonicvibes_capture_ops = { 901 /* open: */ snd_sonicvibes_capture_open, 902 /* close: */ snd_sonicvibes_capture_close, 903 /* ioctl: */ snd_pcm_lib_ioctl, 904 /* hw_params:*/ snd_sonicvibes_hw_params, 905 /* hw_free: */ snd_sonicvibes_hw_free, 906 /* prepare: */ snd_sonicvibes_capture_prepare, 907 /* trigger: */ snd_sonicvibes_capture_trigger, 908 /* pointer: */ snd_sonicvibes_capture_pointer, 909 0, 0 834 static struct snd_pcm_ops snd_sonicvibes_capture_ops = { 835 .open = snd_sonicvibes_capture_open, 836 .close = snd_sonicvibes_capture_close, 837 .ioctl = snd_pcm_lib_ioctl, 838 .hw_params = snd_sonicvibes_hw_params, 839 .hw_free = snd_sonicvibes_hw_free, 840 .prepare = snd_sonicvibes_capture_prepare, 841 .trigger = snd_sonicvibes_capture_trigger, 842 .pointer = snd_sonicvibes_capture_pointer, 910 843 }; 911 #else 912 static snd_pcm_ops_t snd_sonicvibes_playback_ops = { 913 open: snd_sonicvibes_playback_open, 914 close: snd_sonicvibes_playback_close, 915 ioctl: snd_pcm_lib_ioctl, 916 hw_params: snd_sonicvibes_hw_params, 917 hw_free: snd_sonicvibes_hw_free, 918 prepare: snd_sonicvibes_playback_prepare, 919 trigger: snd_sonicvibes_playback_trigger, 920 pointer: snd_sonicvibes_playback_pointer, 921 }; 922 923 static snd_pcm_ops_t snd_sonicvibes_capture_ops = { 924 open: snd_sonicvibes_capture_open, 925 close: snd_sonicvibes_capture_close, 926 ioctl: snd_pcm_lib_ioctl, 927 hw_params: snd_sonicvibes_hw_params, 928 hw_free: snd_sonicvibes_hw_free, 929 prepare: snd_sonicvibes_capture_prepare, 930 trigger: snd_sonicvibes_capture_trigger, 931 pointer: snd_sonicvibes_capture_pointer, 932 }; 933 #endif 934 935 static void snd_sonicvibes_pcm_free(snd_pcm_t *pcm) 936 { 937 sonicvibes_t *sonic = snd_magic_cast(sonicvibes_t, pcm->private_data, return); 938 sonic->pcm = NULL; 939 snd_pcm_lib_preallocate_free_for_all(pcm); 940 } 941 942 static int __init snd_sonicvibes_pcm(sonicvibes_t * sonic, int device, snd_pcm_t ** rpcm) 943 { 944 snd_pcm_t *pcm; 844 845 static int __devinit snd_sonicvibes_pcm(struct sonicvibes * sonic, int device, struct snd_pcm ** rpcm) 846 { 847 struct snd_pcm *pcm; 945 848 int err; 946 849 … … 948 851 return err; 949 852 snd_assert(pcm != NULL, return -EINVAL); 853 950 854 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sonicvibes_playback_ops); 951 855 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_sonicvibes_capture_ops); 952 856 953 857 pcm->private_data = sonic; 954 pcm->private_free = snd_sonicvibes_pcm_free;955 858 pcm->info_flags = 0; 956 859 strcpy(pcm->name, "S3 SonicVibes"); 957 860 sonic->pcm = pcm; 958 861 959 snd_pcm_lib_preallocate_pci_pages_for_all(sonic->pci, pcm, 64*1024, 128*1024); 862 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 863 snd_dma_pci_data(sonic->pci), 64*1024, 128*1024); 960 864 961 865 if (rpcm) … … 968 872 */ 969 873 970 #ifdef TARGET_OS2971 874 #define SONICVIBES_MUX(xname, xindex) \ 972 { SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, xindex, \ 973 0, 0,snd_sonicvibes_info_mux, \ 974 snd_sonicvibes_get_mux, snd_sonicvibes_put_mux, 0} 975 #else 976 #define SONICVIBES_MUX(xname, xindex) \ 977 { iface: SNDRV_CTL_ELEM_IFACE_MIXER, name: xname, index: xindex, \ 978 info: snd_sonicvibes_info_mux, \ 979 get: snd_sonicvibes_get_mux, put: snd_sonicvibes_put_mux } 980 #endif 981 982 static int snd_sonicvibes_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 875 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 876 .info = snd_sonicvibes_info_mux, \ 877 .get = snd_sonicvibes_get_mux, .put = snd_sonicvibes_put_mux } 878 879 static int snd_sonicvibes_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 983 880 { 984 881 static char *texts[7] = { … … 995 892 } 996 893 997 static int snd_sonicvibes_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 998 { 999 sonicvibes_t *sonic = snd_kcontrol_chip(kcontrol); 1000 unsigned long flags; 894 static int snd_sonicvibes_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 895 { 896 struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol); 1001 897 1002 spin_lock_irq save(&sonic->reg_lock, flags);898 spin_lock_irq(&sonic->reg_lock); 1003 899 ucontrol->value.enumerated.item[0] = ((snd_sonicvibes_in1(sonic, SV_IREG_LEFT_ADC) & SV_RECSRC_OUT) >> 5) - 1; 1004 900 ucontrol->value.enumerated.item[1] = ((snd_sonicvibes_in1(sonic, SV_IREG_RIGHT_ADC) & SV_RECSRC_OUT) >> 5) - 1; 1005 spin_unlock_irqrestore(&sonic->reg_lock, flags); 1006 return 0; 1007 } 1008 1009 static int snd_sonicvibes_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1010 { 1011 sonicvibes_t *sonic = snd_kcontrol_chip(kcontrol); 1012 unsigned long flags; 901 spin_unlock_irq(&sonic->reg_lock); 902 return 0; 903 } 904 905 static int snd_sonicvibes_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 906 { 907 struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol); 1013 908 unsigned short left, right, oval1, oval2; 1014 909 int change; … … 1019 914 left = (ucontrol->value.enumerated.item[0] + 1) << 5; 1020 915 right = (ucontrol->value.enumerated.item[1] + 1) << 5; 1021 spin_lock_irq save(&sonic->reg_lock, flags);916 spin_lock_irq(&sonic->reg_lock); 1022 917 oval1 = snd_sonicvibes_in1(sonic, SV_IREG_LEFT_ADC); 1023 918 oval2 = snd_sonicvibes_in1(sonic, SV_IREG_RIGHT_ADC); … … 1027 922 snd_sonicvibes_out1(sonic, SV_IREG_LEFT_ADC, left); 1028 923 snd_sonicvibes_out1(sonic, SV_IREG_RIGHT_ADC, right); 1029 spin_unlock_irq restore(&sonic->reg_lock, flags);924 spin_unlock_irq(&sonic->reg_lock); 1030 925 return change; 1031 926 } 1032 927 1033 #ifdef TARGET_OS21034 928 #define SONICVIBES_SINGLE(xname, xindex, reg, shift, mask, invert) \ 1035 { SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, xindex, \ 1036 0, 0, snd_sonicvibes_info_single, \ 1037 snd_sonicvibes_get_single, snd_sonicvibes_put_single, \ 1038 reg | (shift << 8) | (mask << 16) | (invert << 24) } 1039 #else 1040 #define SONICVIBES_SINGLE(xname, xindex, reg, shift, mask, invert) \ 1041 { iface: SNDRV_CTL_ELEM_IFACE_MIXER, name: xname, index: xindex, \ 1042 info: snd_sonicvibes_info_single, \ 1043 get: snd_sonicvibes_get_single, put: snd_sonicvibes_put_single, \ 1044 private_value: reg | (shift << 8) | (mask << 16) | (invert << 24) } 1045 #endif 1046 1047 static int snd_sonicvibes_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 929 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 930 .info = snd_sonicvibes_info_single, \ 931 .get = snd_sonicvibes_get_single, .put = snd_sonicvibes_put_single, \ 932 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } 933 934 static int snd_sonicvibes_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1048 935 { 1049 936 int mask = (kcontrol->private_value >> 16) & 0xff; … … 1056 943 } 1057 944 1058 static int snd_sonicvibes_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1059 { 1060 sonicvibes_t *sonic = snd_kcontrol_chip(kcontrol); 1061 unsigned long flags; 945 static int snd_sonicvibes_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 946 { 947 struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol); 1062 948 int reg = kcontrol->private_value & 0xff; 1063 949 int shift = (kcontrol->private_value >> 8) & 0xff; … … 1065 951 int invert = (kcontrol->private_value >> 24) & 0xff; 1066 952 1067 spin_lock_irq save(&sonic->reg_lock, flags);953 spin_lock_irq(&sonic->reg_lock); 1068 954 ucontrol->value.integer.value[0] = (snd_sonicvibes_in1(sonic, reg)>> shift) & mask; 1069 spin_unlock_irq restore(&sonic->reg_lock, flags);955 spin_unlock_irq(&sonic->reg_lock); 1070 956 if (invert) 1071 957 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; … … 1073 959 } 1074 960 1075 static int snd_sonicvibes_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1076 { 1077 sonicvibes_t *sonic = snd_kcontrol_chip(kcontrol); 1078 unsigned long flags; 961 static int snd_sonicvibes_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 962 { 963 struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol); 1079 964 int reg = kcontrol->private_value & 0xff; 1080 965 int shift = (kcontrol->private_value >> 8) & 0xff; … … 1088 973 val = mask - val; 1089 974 val <<= shift; 1090 spin_lock_irq save(&sonic->reg_lock, flags);975 spin_lock_irq(&sonic->reg_lock); 1091 976 oval = snd_sonicvibes_in1(sonic, reg); 1092 977 val = (oval & ~(mask << shift)) | val; 1093 978 change = val != oval; 1094 979 snd_sonicvibes_out1(sonic, reg, val); 1095 spin_unlock_irq restore(&sonic->reg_lock, flags);980 spin_unlock_irq(&sonic->reg_lock); 1096 981 return change; 1097 982 } 1098 983 1099 #ifdef TARGET_OS21100 984 #define SONICVIBES_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ 1101 { SNDRV_CTL_ELEM_IFACE_MIXER, 0, 0, xname, xindex, \ 1102 0, 0, snd_sonicvibes_info_double, \ 1103 snd_sonicvibes_get_double, snd_sonicvibes_put_double, \ 1104 left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } 1105 #else 1106 #define SONICVIBES_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ 1107 { iface: SNDRV_CTL_ELEM_IFACE_MIXER, name: xname, index: xindex, \ 1108 info: snd_sonicvibes_info_double, \ 1109 get: snd_sonicvibes_get_double, put: snd_sonicvibes_put_double, \ 1110 private_value: left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } 1111 #endif 1112 1113 static int snd_sonicvibes_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 985 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 986 .info = snd_sonicvibes_info_double, \ 987 .get = snd_sonicvibes_get_double, .put = snd_sonicvibes_put_double, \ 988 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } 989 990 static int snd_sonicvibes_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1114 991 { 1115 992 int mask = (kcontrol->private_value >> 24) & 0xff; … … 1122 999 } 1123 1000 1124 static int snd_sonicvibes_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1125 { 1126 sonicvibes_t *sonic = snd_kcontrol_chip(kcontrol); 1127 unsigned long flags; 1001 static int snd_sonicvibes_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1002 { 1003 struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol); 1128 1004 int left_reg = kcontrol->private_value & 0xff; 1129 1005 int right_reg = (kcontrol->private_value >> 8) & 0xff; … … 1133 1009 int invert = (kcontrol->private_value >> 22) & 1; 1134 1010 1135 spin_lock_irq save(&sonic->reg_lock, flags);1011 spin_lock_irq(&sonic->reg_lock); 1136 1012 ucontrol->value.integer.value[0] = (snd_sonicvibes_in1(sonic, left_reg) >> shift_left) & mask; 1137 1013 ucontrol->value.integer.value[1] = (snd_sonicvibes_in1(sonic, right_reg) >> shift_right) & mask; 1138 spin_unlock_irq restore(&sonic->reg_lock, flags);1014 spin_unlock_irq(&sonic->reg_lock); 1139 1015 if (invert) { 1140 1016 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; … … 1144 1020 } 1145 1021 1146 static int snd_sonicvibes_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1147 { 1148 sonicvibes_t *sonic = snd_kcontrol_chip(kcontrol); 1149 unsigned long flags; 1022 static int snd_sonicvibes_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1023 { 1024 struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol); 1150 1025 int left_reg = kcontrol->private_value & 0xff; 1151 1026 int right_reg = (kcontrol->private_value >> 8) & 0xff; … … 1165 1040 val1 <<= shift_left; 1166 1041 val2 <<= shift_right; 1167 spin_lock_irq save(&sonic->reg_lock, flags);1042 spin_lock_irq(&sonic->reg_lock); 1168 1043 oval1 = snd_sonicvibes_in1(sonic, left_reg); 1169 1044 oval2 = snd_sonicvibes_in1(sonic, right_reg); … … 1173 1048 snd_sonicvibes_out1(sonic, left_reg, val1); 1174 1049 snd_sonicvibes_out1(sonic, right_reg, val2); 1175 spin_unlock_irq restore(&sonic->reg_lock, flags);1050 spin_unlock_irq(&sonic->reg_lock); 1176 1051 return change; 1177 1052 } 1178 1053 1179 #define SONICVIBES_CONTROLS (sizeof(snd_sonicvibes_controls)/sizeof(snd_kcontrol_new_t)) 1180 1181 static snd_kcontrol_new_t snd_sonicvibes_controls[] = { 1054 static struct snd_kcontrol_new snd_sonicvibes_controls[] __devinitdata = { 1182 1055 SONICVIBES_DOUBLE("Capture Volume", 0, SV_IREG_LEFT_ADC, SV_IREG_RIGHT_ADC, 0, 0, 15, 0), 1183 1056 SONICVIBES_DOUBLE("Aux Playback Switch", 0, SV_IREG_LEFT_AUX1, SV_IREG_RIGHT_AUX1, 7, 7, 1, 1), … … 1203 1076 }; 1204 1077 1205 static void snd_sonicvibes_master_free(s nd_kcontrol_t*kcontrol)1206 { 1207 s onicvibes_t *sonic = snd_magic_cast(sonicvibes_t, _snd_kcontrol_chip(kcontrol), return);1078 static void snd_sonicvibes_master_free(struct snd_kcontrol *kcontrol) 1079 { 1080 struct sonicvibes *sonic = snd_kcontrol_chip(kcontrol); 1208 1081 sonic->master_mute = NULL; 1209 1082 sonic->master_volume = NULL; 1210 1083 } 1211 1084 1212 static int __init snd_sonicvibes_mixer(sonicvibes_t * sonic) 1213 { 1214 snd_card_t *card; 1215 snd_kcontrol_t *kctl; 1216 int idx, err; 1085 static int __devinit snd_sonicvibes_mixer(struct sonicvibes * sonic) 1086 { 1087 struct snd_card *card; 1088 struct snd_kcontrol *kctl; 1089 unsigned int idx; 1090 int err; 1217 1091 1218 1092 snd_assert(sonic != NULL && sonic->card != NULL, return -EINVAL); … … 1220 1094 strcpy(card->mixername, "S3 SonicVibes"); 1221 1095 1222 for (idx = 0; idx < SONICVIBES_CONTROLS; idx++) {1096 for (idx = 0; idx < ARRAY_SIZE(snd_sonicvibes_controls); idx++) { 1223 1097 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_sonicvibes_controls[idx], sonic))) < 0) 1224 1098 return err; … … 1235 1109 */ 1236 1110 1237 static void snd_sonicvibes_proc_read(s nd_info_entry_t*entry,1238 s nd_info_buffer_t *buffer)1239 { 1240 s onicvibes_t *sonic = snd_magic_cast(sonicvibes_t, entry->private_data, return);1111 static void snd_sonicvibes_proc_read(struct snd_info_entry *entry, 1112 struct snd_info_buffer *buffer) 1113 { 1114 struct sonicvibes *sonic = entry->private_data; 1241 1115 unsigned char tmp; 1242 1116 … … 1265 1139 } 1266 1140 1267 static void __init snd_sonicvibes_proc_init(sonicvibes_t * sonic) 1268 { 1269 snd_info_entry_t *entry; 1270 1271 if ((entry = snd_info_create_card_entry(sonic->card, "sonicvibes", sonic->card->proc_root)) != NULL) { 1272 entry->content = SNDRV_INFO_CONTENT_TEXT; 1273 entry->private_data = sonic; 1274 entry->mode = S_IFREG | S_IRUGO | S_IWUSR; 1275 entry->c.text.read_size = 256; 1276 entry->c.text.read = snd_sonicvibes_proc_read; 1277 if (snd_info_register(entry) < 0) { 1278 snd_info_free_entry(entry); 1279 entry = NULL; 1280 } 1281 } 1282 sonic->proc_entry = entry; 1283 } 1284 1285 static void snd_sonicvibes_proc_done(sonicvibes_t * sonic) 1286 { 1287 if (sonic->proc_entry) { 1288 snd_info_unregister(sonic->proc_entry); 1289 sonic->proc_entry = NULL; 1290 } 1141 static void __devinit snd_sonicvibes_proc_init(struct sonicvibes * sonic) 1142 { 1143 struct snd_info_entry *entry; 1144 1145 if (! snd_card_proc_new(sonic->card, "sonicvibes", &entry)) 1146 snd_info_set_text_ops(entry, sonic, snd_sonicvibes_proc_read); 1291 1147 } 1292 1148 … … 1295 1151 */ 1296 1152 1297 static snd_kcontrol_new_t snd_sonicvibes_game_control = 1153 #ifdef SUPPORT_JOYSTICK 1154 static struct snd_kcontrol_new snd_sonicvibes_game_control __devinitdata = 1298 1155 SONICVIBES_SINGLE("Joystick Speed", 0, SV_IREG_GAME_PORT, 1, 15, 0); 1299 1156 1300 static int snd_sonicvibes_free(sonicvibes_t *sonic) 1301 { 1302 snd_sonicvibes_proc_done(sonic); 1157 static int __devinit snd_sonicvibes_create_gameport(struct sonicvibes *sonic) 1158 { 1159 struct gameport *gp; 1160 1161 sonic->gameport = gp = gameport_allocate_port(); 1162 if (!gp) { 1163 printk(KERN_ERR "sonicvibes: cannot allocate memory for gameport\n"); 1164 return -ENOMEM; 1165 } 1166 1167 gameport_set_name(gp, "SonicVibes Gameport"); 1168 gameport_set_phys(gp, "pci%s/gameport0", pci_name(sonic->pci)); 1169 gameport_set_dev_parent(gp, &sonic->pci->dev); 1170 gp->io = sonic->game_port; 1171 1172 gameport_register_port(gp); 1173 1174 snd_ctl_add(sonic->card, snd_ctl_new1(&snd_sonicvibes_game_control, sonic)); 1175 1176 return 0; 1177 } 1178 1179 static void snd_sonicvibes_free_gameport(struct sonicvibes *sonic) 1180 { 1181 if (sonic->gameport) { 1182 gameport_unregister_port(sonic->gameport); 1183 sonic->gameport = NULL; 1184 } 1185 } 1186 #else 1187 static inline int snd_sonicvibes_create_gameport(struct sonicvibes *sonic) { return -ENOSYS; } 1188 static inline void snd_sonicvibes_free_gameport(struct sonicvibes *sonic) { } 1189 #endif 1190 1191 static int snd_sonicvibes_free(struct sonicvibes *sonic) 1192 { 1193 snd_sonicvibes_free_gameport(sonic); 1303 1194 pci_write_config_dword(sonic->pci, 0x40, sonic->dmaa_port); 1304 1195 pci_write_config_dword(sonic->pci, 0x48, sonic->dmac_port); 1305 if (sonic->res_sb_port)1306 release_resource(sonic->res_sb_port);1307 if (sonic->res_enh_port)1308 release_resource(sonic->res_enh_port);1309 if (sonic->res_synth_port)1310 release_resource(sonic->res_synth_port);1311 if (sonic->res_midi_port)1312 release_resource(sonic->res_midi_port);1313 if (sonic->res_dmaa)1314 release_resource(sonic->res_dmaa);1315 if (sonic->res_dmac)1316 release_resource(sonic->res_dmac);1317 1196 if (sonic->irq >= 0) 1318 free_irq(sonic->irq, (void *)sonic); 1319 snd_magic_kfree(sonic); 1320 return 0; 1321 } 1322 1323 static int snd_sonicvibes_dev_free(snd_device_t *device) 1324 { 1325 sonicvibes_t *sonic = snd_magic_cast(sonicvibes_t, device->device_data, return -ENXIO); 1197 free_irq(sonic->irq, sonic); 1198 release_and_free_resource(sonic->res_dmaa); 1199 release_and_free_resource(sonic->res_dmac); 1200 pci_release_regions(sonic->pci); 1201 pci_disable_device(sonic->pci); 1202 kfree(sonic); 1203 return 0; 1204 } 1205 1206 static int snd_sonicvibes_dev_free(struct snd_device *device) 1207 { 1208 struct sonicvibes *sonic = device->device_data; 1326 1209 return snd_sonicvibes_free(sonic); 1327 1210 } 1328 1211 1329 static int __ init snd_sonicvibes_create(snd_card_t *card,1212 static int __devinit snd_sonicvibes_create(struct snd_card *card, 1330 1213 struct pci_dev *pci, 1331 1214 int reverb, 1332 1215 int mge, 1333 s onicvibes_t** rsonic)1334 { 1335 s onicvibes_t*sonic;1216 struct sonicvibes ** rsonic) 1217 { 1218 struct sonicvibes *sonic; 1336 1219 unsigned int dmaa, dmac; 1337 1220 int err; 1338 #ifdef TARGET_OS2 1339 static snd_device_ops_t ops = { 1340 snd_sonicvibes_dev_free,0,0,0 1221 static struct snd_device_ops ops = { 1222 .dev_free = snd_sonicvibes_dev_free, 1341 1223 }; 1342 #else1343 static snd_device_ops_t ops = {1344 dev_free: snd_sonicvibes_dev_free,1345 };1346 #endif1347 1224 1348 1225 *rsonic = NULL; … … 1351 1228 return err; 1352 1229 /* check, if we can restrict PCI DMA transfers to 24 bits */ 1353 if (!pci_dma_supported(pci, 0x00ffffff)) { 1354 snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); 1230 if (pci_set_dma_mask(pci, DMA_24BIT_MASK) < 0 || 1231 pci_set_consistent_dma_mask(pci, DMA_24BIT_MASK) < 0) { 1232 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n"); 1233 pci_disable_device(pci); 1355 1234 return -ENXIO; 1356 1235 } 1357 pci_set_dma_mask(pci, 0x00ffffff); 1358 1359 sonic = snd_magic_kcalloc(sonicvibes_t, 0, GFP_KERNEL);1360 if (sonic == NULL)1236 1237 sonic = kzalloc(sizeof(*sonic), GFP_KERNEL); 1238 if (sonic == NULL) { 1239 pci_disable_device(pci); 1361 1240 return -ENOMEM; 1241 } 1362 1242 spin_lock_init(&sonic->reg_lock); 1363 1243 sonic->card = card; 1364 1244 sonic->pci = pci; 1365 1245 sonic->irq = -1; 1246 1247 if ((err = pci_request_regions(pci, "S3 SonicVibes")) < 0) { 1248 kfree(sonic); 1249 pci_disable_device(pci); 1250 return err; 1251 } 1252 1366 1253 sonic->sb_port = pci_resource_start(pci, 0); 1367 if ((sonic->res_sb_port = request_region(sonic->sb_port, 0x10, "S3 SonicVibes SB")) == NULL) { 1254 sonic->enh_port = pci_resource_start(pci, 1); 1255 sonic->synth_port = pci_resource_start(pci, 2); 1256 sonic->midi_port = pci_resource_start(pci, 3); 1257 sonic->game_port = pci_resource_start(pci, 4); 1258 1259 if (request_irq(pci->irq, snd_sonicvibes_interrupt, IRQF_SHARED, 1260 "S3 SonicVibes", sonic)) { 1261 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); 1368 1262 snd_sonicvibes_free(sonic); 1369 snd_printk("unable to grab SB port at 0x%lx-0x%lx\n", sonic->sb_port, sonic->sb_port + 0x10 - 1);1370 return -EBUSY;1371 }1372 sonic->enh_port = pci_resource_start(pci, 1);1373 if ((sonic->res_enh_port = request_region(sonic->enh_port, 0x10, "S3 SonicVibes Enhanced")) == NULL) {1374 snd_sonicvibes_free(sonic);1375 snd_printk("unable to grab PCM port at 0x%lx-0x%lx\n", sonic->enh_port, sonic->enh_port + 0x10 - 1);1376 return -EBUSY;1377 }1378 sonic->synth_port = pci_resource_start(pci, 2);1379 if ((sonic->res_synth_port = request_region(sonic->synth_port, 4, "S3 SonicVibes Synth")) == NULL) {1380 snd_sonicvibes_free(sonic);1381 snd_printk("unable to grab synth port at 0x%lx-0x%lx\n", sonic->synth_port, sonic->synth_port + 4 - 1);1382 return -EBUSY;1383 }1384 sonic->midi_port = pci_resource_start(pci, 3);1385 if ((sonic->res_midi_port = request_region(sonic->midi_port, 4, "S3 SonicVibes Midi")) == NULL) {1386 snd_sonicvibes_free(sonic);1387 snd_printk("unable to grab MIDI port at 0x%lx-0x%lx\n", sonic->midi_port, sonic->midi_port + 4 - 1);1388 return -EBUSY;1389 }1390 sonic->game_port = pci_resource_start(pci, 4);1391 if (request_irq(pci->irq, snd_sonicvibes_interrupt, SA_INTERRUPT|SA_SHIRQ, "S3 SonicVibes", (void *)sonic)) {1392 snd_magic_kfree(sonic);1393 snd_printk("unable to grab IRQ %d\n", pci->irq);1394 1263 return -EBUSY; 1395 1264 } … … 1398 1267 pci_read_config_dword(pci, 0x40, &dmaa); 1399 1268 pci_read_config_dword(pci, 0x48, &dmac); 1400 snd_dmaio &= ~0x0f;1269 dmaio &= ~0x0f; 1401 1270 dmaa &= ~0x0f; 1402 1271 dmac &= ~0x0f; 1403 1272 if (!dmaa) { 1404 dmaa = snd_dmaio;1405 snd_dmaio += 0x10;1406 snd_printk( "BIOS did not allocate DDMA channel A i/o, allocated at 0x%x\n", dmaa);1273 dmaa = dmaio; 1274 dmaio += 0x10; 1275 snd_printk(KERN_INFO "BIOS did not allocate DDMA channel A i/o, allocated at 0x%x\n", dmaa); 1407 1276 } 1408 1277 if (!dmac) { 1409 dmac = snd_dmaio;1410 snd_dmaio += 0x10;1411 snd_printk( "BIOS did not allocate DDMA channel C i/o, allocated at 0x%x\n", dmac);1278 dmac = dmaio; 1279 dmaio += 0x10; 1280 snd_printk(KERN_INFO "BIOS did not allocate DDMA channel C i/o, allocated at 0x%x\n", dmac); 1412 1281 } 1413 1282 pci_write_config_dword(pci, 0x40, dmaa); … … 1416 1285 if ((sonic->res_dmaa = request_region(dmaa, 0x10, "S3 SonicVibes DDMA-A")) == NULL) { 1417 1286 snd_sonicvibes_free(sonic); 1418 snd_printk( "unable to grab DDMA-A port at 0x%x-0x%x\n", dmaa, dmaa + 0x10 - 1);1287 snd_printk(KERN_ERR "unable to grab DDMA-A port at 0x%x-0x%x\n", dmaa, dmaa + 0x10 - 1); 1419 1288 return -EBUSY; 1420 1289 } 1421 1290 if ((sonic->res_dmac = request_region(dmac, 0x10, "S3 SonicVibes DDMA-C")) == NULL) { 1422 1291 snd_sonicvibes_free(sonic); 1423 snd_printk( "unable to grab DDMA-C port at 0x%x-0x%x\n", dmac, dmac + 0x10 - 1);1292 snd_printk(KERN_ERR "unable to grab DDMA-C port at 0x%x-0x%x\n", dmac, dmac + 0x10 - 1); 1424 1293 return -EBUSY; 1425 1294 } … … 1478 1347 #endif 1479 1348 sonic->revision = snd_sonicvibes_in(sonic, SV_IREG_REVISION); 1480 snd_ctl_add(card, snd_ctl_new1(&snd_sonicvibes_game_control, sonic));1481 snd_sonicvibes_proc_init(sonic);1482 1349 1483 1350 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, sonic, &ops)) < 0) { … … 1486 1353 } 1487 1354 1355 snd_sonicvibes_proc_init(sonic); 1356 1357 snd_card_set_dev(card, &pci->dev); 1358 1488 1359 *rsonic = sonic; 1489 1360 return 0; … … 1494 1365 */ 1495 1366 1496 #define SONICVIBES_MIDI_CONTROLS (sizeof(snd_sonicvibes_midi_controls)/sizeof(snd_kcontrol_new_t)) 1497 1498 static snd_kcontrol_new_t snd_sonicvibes_midi_controls[] = { 1367 static struct snd_kcontrol_new snd_sonicvibes_midi_controls[] __devinitdata = { 1499 1368 SONICVIBES_SINGLE("SonicVibes Wave Source RAM", 0, SV_IREG_WAVE_SOURCE, 0, 1, 0), 1500 1369 SONICVIBES_SINGLE("SonicVibes Wave Source RAM+ROM", 0, SV_IREG_WAVE_SOURCE, 1, 1, 0), … … 1504 1373 }; 1505 1374 1506 static void snd_sonicvibes_midi_input_open(mpu401_t* mpu)1507 { 1508 s onicvibes_t *sonic = snd_magic_cast(sonicvibes_t, mpu->private_data, return);1375 static int snd_sonicvibes_midi_input_open(struct snd_mpu401 * mpu) 1376 { 1377 struct sonicvibes *sonic = mpu->private_data; 1509 1378 outb(sonic->irqmask &= ~SV_MIDI_MASK, SV_REG(sonic, IRQMASK)); 1510 } 1511 1512 static void snd_sonicvibes_midi_input_close(mpu401_t * mpu) 1513 { 1514 sonicvibes_t *sonic = snd_magic_cast(sonicvibes_t, mpu->private_data, return); 1379 return 0; 1380 } 1381 1382 static void snd_sonicvibes_midi_input_close(struct snd_mpu401 * mpu) 1383 { 1384 struct sonicvibes *sonic = mpu->private_data; 1515 1385 outb(sonic->irqmask |= SV_MIDI_MASK, SV_REG(sonic, IRQMASK)); 1516 1386 } 1517 1387 1518 static int snd_sonicvibes_midi(sonicvibes_t * sonic, snd_rawmidi_t * rmidi) 1519 { 1520 mpu401_t * mpu = snd_magic_cast(mpu401_t, rmidi->private_data, return -ENXIO); 1521 snd_card_t *card = sonic->card; 1522 snd_rawmidi_str_t *dir; 1523 int idx, err; 1388 static int __devinit snd_sonicvibes_midi(struct sonicvibes * sonic, 1389 struct snd_rawmidi *rmidi) 1390 { 1391 struct snd_mpu401 * mpu = rmidi->private_data; 1392 struct snd_card *card = sonic->card; 1393 struct snd_rawmidi_str *dir; 1394 unsigned int idx; 1395 int err; 1524 1396 1525 1397 mpu->private_data = sonic; … … 1527 1399 mpu->close_input = snd_sonicvibes_midi_input_close; 1528 1400 dir = &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]; 1529 for (idx = 0; idx < SONICVIBES_MIDI_CONTROLS; idx++)1401 for (idx = 0; idx < ARRAY_SIZE(snd_sonicvibes_midi_controls); idx++) 1530 1402 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_sonicvibes_midi_controls[idx], sonic))) < 0) 1531 1403 return err; … … 1533 1405 } 1534 1406 1535 static int __ init snd_sonic_probe(struct pci_dev *pci,1536 const struct pci_device_id *id)1537 { 1538 static int dev = 0;1539 s nd_card_t*card;1540 s onicvibes_t*sonic;1541 s nd_rawmidi_t*midi_uart;1542 opl3_t*opl3;1407 static int __devinit snd_sonic_probe(struct pci_dev *pci, 1408 const struct pci_device_id *pci_id) 1409 { 1410 static int dev; 1411 struct snd_card *card; 1412 struct sonicvibes *sonic; 1413 struct snd_rawmidi *midi_uart; 1414 struct snd_opl3 *opl3; 1543 1415 int idx, err; 1544 1416 1545 for ( ; dev < SNDRV_CARDS; dev++) {1546 if (!snd_enable[dev]) {1547 dev++;1548 return -ENOENT;1549 }1550 break;1551 }1552 1417 if (dev >= SNDRV_CARDS) 1553 1418 return -ENODEV; 1419 if (!enable[dev]) { 1420 dev++; 1421 return -ENOENT; 1422 } 1554 1423 1555 card = snd_card_new( snd_index[dev], snd_id[dev], THIS_MODULE, 0);1424 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1556 1425 if (card == NULL) 1557 1426 return -ENOMEM; … … 1564 1433 } 1565 1434 if ((err = snd_sonicvibes_create(card, pci, 1566 snd_reverb[dev] ? 1 : 0,1567 snd_mge[dev] ? 1 : 0,1435 reverb[dev] ? 1 : 0, 1436 mge[dev] ? 1 : 0, 1568 1437 &sonic)) < 0) { 1569 1438 snd_card_free(card); 1570 1439 return err; 1571 1440 } 1441 1442 strcpy(card->driver, "SonicVibes"); 1443 strcpy(card->shortname, "S3 SonicVibes"); 1444 sprintf(card->longname, "%s rev %i at 0x%llx, irq %i", 1445 card->shortname, 1446 sonic->revision, 1447 (unsigned long long)pci_resource_start(pci, 1), 1448 sonic->irq); 1449 1572 1450 if ((err = snd_sonicvibes_pcm(sonic, 0, NULL)) < 0) { 1573 1451 snd_card_free(card); … … 1578 1456 return err; 1579 1457 } 1580 1581 1458 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SONICVIBES, 1459 sonic->midi_port, MPU401_INFO_INTEGRATED, 1582 1460 sonic->irq, 0, 1583 1461 &midi_uart)) < 0) { … … 1596 1474 return err; 1597 1475 } 1598 strcpy(card->driver, "SonicVibes"); 1599 strcpy(card->shortname, "S3 SonicVibes"); 1600 sprintf(card->longname, "%s rev %i at 0x%lx, irq %i", 1601 card->shortname, 1602 sonic->revision, 1603 pci_resource_start(pci, 1), 1604 sonic->irq); 1476 1477 snd_sonicvibes_create_gameport(sonic); 1605 1478 1606 1479 if ((err = snd_card_register(card)) < 0) { … … 1609 1482 } 1610 1483 1611 PCI_SET_DRIVER_DATA(pci, card);1484 pci_set_drvdata(pci, card); 1612 1485 dev++; 1613 1486 return 0; 1614 1487 } 1615 1488 1616 static void __ exit snd_sonic_remove(struct pci_dev *pci)1617 { 1618 snd_card_free( PCI_GET_DRIVER_DATA(pci));1619 PCI_SET_DRIVER_DATA(pci, NULL);1489 static void __devexit snd_sonic_remove(struct pci_dev *pci) 1490 { 1491 snd_card_free(pci_get_drvdata(pci)); 1492 pci_set_drvdata(pci, NULL); 1620 1493 } 1621 1494 1622 1495 static struct pci_driver driver = { 1623 #ifdef TARGET_OS2 1624 0, 0, 0, 1625 "S3 SonicVibes", 1626 snd_sonic_ids, 1627 snd_sonic_probe, 1628 snd_sonic_remove, 1629 0, 0 1630 #else 1631 name: "S3 SonicVibes", 1632 id_table: snd_sonic_ids, 1633 probe: snd_sonic_probe, 1634 remove: snd_sonic_remove, 1635 #endif 1496 .name = "S3 SonicVibes", 1497 .id_table = snd_sonic_ids, 1498 .probe = snd_sonic_probe, 1499 .remove = __devexit_p(snd_sonic_remove), 1636 1500 }; 1637 1501 1638 1502 static int __init alsa_card_sonicvibes_init(void) 1639 1503 { 1640 int err; 1641 1642 if ((err = pci_module_init(&driver)) < 0) { 1643 #ifdef MODULE 1644 // snd_printk("S3 SonicVibes soundcard not found or device busy\n"); 1645 #endif 1646 return err; 1647 } 1648 return 0; 1504 return pci_register_driver(&driver); 1649 1505 } 1650 1506 … … 1656 1512 module_init(alsa_card_sonicvibes_init) 1657 1513 module_exit(alsa_card_sonicvibes_exit) 1658 1659 #ifndef MODULE1660 1661 /* format is: snd-card-sonicvibes=snd_enable,snd_index,snd_id,1662 snd_reverb,snd_mge,snd_dmaio */1663 1664 static int __init alsa_card_sonicvibes_setup(char *str)1665 {1666 static unsigned __initdata nr_dev = 0;1667 1668 if (nr_dev >= SNDRV_CARDS)1669 return 0;1670 (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&1671 get_option(&str,&snd_index[nr_dev]) == 2 &&1672 get_id(&str,&snd_id[nr_dev]) == 2 &&1673 get_option(&str,&snd_reverb[nr_dev]) == 2 &&1674 get_option(&str,&snd_mge[nr_dev]) == 2 &&1675 get_option(&str,(int *)&snd_dmaio) == 2);1676 nr_dev++;1677 return 1;1678 }1679 1680 __setup("snd-card-sonicvibes=", alsa_card_sonicvibes_setup);1681 1682 #endif /* ifndef MODULE */
Note:
See TracChangeset
for help on using the changeset viewer.