aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper Juhl <jesper.juhl@gmail.com>2006-06-23 05:05:26 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-23 10:43:04 -0400
commit2eebb1925d25cfd7e7cd2eb18ac4d4e6d189dba0 (patch)
treea4257f771edf0b1809eba1999447692741caeafa
parent9ada7340987aa24395809570840c7c6847044f52 (diff)
[PATCH] OSS: cs46xx cleanup and tiny bugfix
Here's a patch for cs46xx that - (mostly) cleans up the cs46xx driver according to CodingStyle - removes a bunch of pointless casts - fixes a small, potential use of uninitialized variable, bug - reduces the size of the compiled code by 36 bytes - reduces the size of the source file by 1831 bytes I know I should probably have split this into bits, but since I only thought of that *after* doing all the edits, splitting it up would have been a royal pain. And since these are all pretty trivial changes I thought I'd just submit the one huge patch and hope people could live with it (if not, then just tell me and I'll split it). The bug fix that's in there may be hard to spot, so I'll point it out. It's the - int val, valsave, mapped, ret; + int val, valsave, ret; + int mapped = 0; bit. Without that change we may use `mapped' uninitialized if, in cs_ioctl, the first test of "if(state)" is false and the second "if(state)" test is true. Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--sound/oss/cs46xx.c1272
1 files changed, 489 insertions, 783 deletions
diff --git a/sound/oss/cs46xx.c b/sound/oss/cs46xx.c
index 53881bc91bba..994c71e986e4 100644
--- a/sound/oss/cs46xx.c
+++ b/sound/oss/cs46xx.c
@@ -147,7 +147,7 @@
147 * that should be printed on any released driver. 147 * that should be printed on any released driver.
148 */ 148 */
149#if CSDEBUG 149#if CSDEBUG
150#define CS_DBGOUT(mask,level,x) if((cs_debuglevel >= (level)) && ((mask) & cs_debugmask)) {x;} 150#define CS_DBGOUT(mask,level,x) if ((cs_debuglevel >= (level)) && ((mask) & cs_debugmask)) {x;}
151#else 151#else
152#define CS_DBGOUT(mask,level,x) 152#define CS_DBGOUT(mask,level,x)
153#endif 153#endif
@@ -175,19 +175,19 @@
175#define CS_IOCTL_CMD_RESUME 0x2 // resume 175#define CS_IOCTL_CMD_RESUME 0x2 // resume
176 176
177#if CSDEBUG 177#if CSDEBUG
178static unsigned long cs_debuglevel=1; /* levels range from 1-9 */ 178static unsigned long cs_debuglevel = 1; /* levels range from 1-9 */
179module_param(cs_debuglevel, ulong, 0644); 179module_param(cs_debuglevel, ulong, 0644);
180static unsigned long cs_debugmask=CS_INIT | CS_ERROR; /* use CS_DBGOUT with various mask values */ 180static unsigned long cs_debugmask = CS_INIT | CS_ERROR; /* use CS_DBGOUT with various mask values */
181module_param(cs_debugmask, ulong, 0644); 181module_param(cs_debugmask, ulong, 0644);
182#endif 182#endif
183static unsigned long hercules_egpio_disable; /* if non-zero set all EGPIO to 0 */ 183static unsigned long hercules_egpio_disable; /* if non-zero set all EGPIO to 0 */
184module_param(hercules_egpio_disable, ulong, 0); 184module_param(hercules_egpio_disable, ulong, 0);
185static unsigned long initdelay=700; /* PM delay in millisecs */ 185static unsigned long initdelay = 700; /* PM delay in millisecs */
186module_param(initdelay, ulong, 0); 186module_param(initdelay, ulong, 0);
187static unsigned long powerdown=-1; /* turn on/off powerdown processing in driver */ 187static unsigned long powerdown = -1; /* turn on/off powerdown processing in driver */
188module_param(powerdown, ulong, 0); 188module_param(powerdown, ulong, 0);
189#define DMABUF_DEFAULTORDER 3 189#define DMABUF_DEFAULTORDER 3
190static unsigned long defaultorder=DMABUF_DEFAULTORDER; 190static unsigned long defaultorder = DMABUF_DEFAULTORDER;
191module_param(defaultorder, ulong, 0); 191module_param(defaultorder, ulong, 0);
192 192
193static int external_amp; 193static int external_amp;
@@ -200,8 +200,8 @@ module_param(thinkpad, bool, 0);
200* powerdown. also set thinkpad to 1 to disable powerdown, 200* powerdown. also set thinkpad to 1 to disable powerdown,
201* but also to enable the clkrun functionality. 201* but also to enable the clkrun functionality.
202*/ 202*/
203static unsigned cs_powerdown=1; 203static unsigned cs_powerdown = 1;
204static unsigned cs_laptop_wait=1; 204static unsigned cs_laptop_wait = 1;
205 205
206/* An instance of the 4610 channel */ 206/* An instance of the 4610 channel */
207struct cs_channel 207struct cs_channel
@@ -319,7 +319,7 @@ struct cs_card {
319 atomic_t mixer_use_cnt; 319 atomic_t mixer_use_cnt;
320 320
321 /* PCI device stuff */ 321 /* PCI device stuff */
322 struct pci_dev * pci_dev; 322 struct pci_dev *pci_dev;
323 struct list_head list; 323 struct list_head list;
324 324
325 unsigned int pctl, cctl; /* Hardware DMA flag sets */ 325 unsigned int pctl, cctl; /* Hardware DMA flag sets */
@@ -384,7 +384,7 @@ struct cs_card {
384static int cs_open_mixdev(struct inode *inode, struct file *file); 384static int cs_open_mixdev(struct inode *inode, struct file *file);
385static int cs_release_mixdev(struct inode *inode, struct file *file); 385static int cs_release_mixdev(struct inode *inode, struct file *file);
386static int cs_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, 386static int cs_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
387 unsigned long arg); 387 unsigned long arg);
388static int cs_hardware_init(struct cs_card *card); 388static int cs_hardware_init(struct cs_card *card);
389static int cs46xx_powerup(struct cs_card *card, unsigned int type); 389static int cs46xx_powerup(struct cs_card *card, unsigned int type);
390static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspendflag); 390static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspendflag);
@@ -423,8 +423,7 @@ static void printioctl(unsigned int x)
423 [SOUND_MIXER_VOLUME] = 9 /* Master Volume */ 423 [SOUND_MIXER_VOLUME] = 9 /* Master Volume */
424 }; 424 };
425 425
426 switch(x) 426 switch (x) {
427 {
428 case SOUND_MIXER_CS_GETDBGMASK: 427 case SOUND_MIXER_CS_GETDBGMASK:
429 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CS_GETDBGMASK: ") ); 428 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CS_GETDBGMASK: ") );
430 break; 429 break;
@@ -521,7 +520,6 @@ static void printioctl(unsigned int x)
521 case SOUND_PCM_READ_FILTER: 520 case SOUND_PCM_READ_FILTER:
522 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_FILTER: ") ); 521 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_FILTER: ") );
523 break; 522 break;
524
525 case SOUND_MIXER_PRIVATE1: 523 case SOUND_MIXER_PRIVATE1:
526 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE1: ") ); 524 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE1: ") );
527 break; 525 break;
@@ -543,10 +541,8 @@ static void printioctl(unsigned int x)
543 case SOUND_OLD_MIXER_INFO: 541 case SOUND_OLD_MIXER_INFO:
544 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_OLD_MIXER_INFO: ") ); 542 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_OLD_MIXER_INFO: ") );
545 break; 543 break;
546
547 default: 544 default:
548 switch (_IOC_NR(x)) 545 switch (_IOC_NR(x)) {
549 {
550 case SOUND_MIXER_VOLUME: 546 case SOUND_MIXER_VOLUME:
551 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_VOLUME: ") ); 547 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_VOLUME: ") );
552 break; 548 break;
@@ -579,14 +575,11 @@ static void printioctl(unsigned int x)
579 break; 575 break;
580 default: 576 default:
581 i = _IOC_NR(x); 577 i = _IOC_NR(x);
582 if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i])) 578 if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i])) {
583 {
584 CS_DBGOUT(CS_IOCTL, 4, printk("UNKNOWN IOCTL: 0x%.8x NR=%d ",x,i) ); 579 CS_DBGOUT(CS_IOCTL, 4, printk("UNKNOWN IOCTL: 0x%.8x NR=%d ",x,i) );
585 } 580 } else {
586 else
587 {
588 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_IOCTL AC9x: 0x%.8x NR=%d ", 581 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_IOCTL AC9x: 0x%.8x NR=%d ",
589 x,i) ); 582 x,i));
590 } 583 }
591 break; 584 break;
592 } 585 }
@@ -601,22 +594,22 @@ static void printioctl(unsigned int x)
601 594
602static void cs461x_poke(struct cs_card *codec, unsigned long reg, unsigned int val) 595static void cs461x_poke(struct cs_card *codec, unsigned long reg, unsigned int val)
603{ 596{
604 writel(val, codec->ba1.idx[(reg >> 16) & 3]+(reg&0xffff)); 597 writel(val, codec->ba1.idx[(reg >> 16) & 3] + (reg & 0xffff));
605} 598}
606 599
607static unsigned int cs461x_peek(struct cs_card *codec, unsigned long reg) 600static unsigned int cs461x_peek(struct cs_card *codec, unsigned long reg)
608{ 601{
609 return readl(codec->ba1.idx[(reg >> 16) & 3]+(reg&0xffff)); 602 return readl(codec->ba1.idx[(reg >> 16) & 3] + (reg & 0xffff));
610} 603}
611 604
612static void cs461x_pokeBA0(struct cs_card *codec, unsigned long reg, unsigned int val) 605static void cs461x_pokeBA0(struct cs_card *codec, unsigned long reg, unsigned int val)
613{ 606{
614 writel(val, codec->ba0+reg); 607 writel(val, codec->ba0 + reg);
615} 608}
616 609
617static unsigned int cs461x_peekBA0(struct cs_card *codec, unsigned long reg) 610static unsigned int cs461x_peekBA0(struct cs_card *codec, unsigned long reg)
618{ 611{
619 return readl(codec->ba0+reg); 612 return readl(codec->ba0 + reg);
620} 613}
621 614
622 615
@@ -625,26 +618,26 @@ static void cs_ac97_set(struct ac97_codec *dev, u8 reg, u16 data);
625 618
626static struct cs_channel *cs_alloc_pcm_channel(struct cs_card *card) 619static struct cs_channel *cs_alloc_pcm_channel(struct cs_card *card)
627{ 620{
628 if(card->channel[1].used==1) 621 if (card->channel[1].used == 1)
629 return NULL; 622 return NULL;
630 card->channel[1].used=1; 623 card->channel[1].used = 1;
631 card->channel[1].num=1; 624 card->channel[1].num = 1;
632 return &card->channel[1]; 625 return &card->channel[1];
633} 626}
634 627
635static struct cs_channel *cs_alloc_rec_pcm_channel(struct cs_card *card) 628static struct cs_channel *cs_alloc_rec_pcm_channel(struct cs_card *card)
636{ 629{
637 if(card->channel[0].used==1) 630 if (card->channel[0].used == 1)
638 return NULL; 631 return NULL;
639 card->channel[0].used=1; 632 card->channel[0].used = 1;
640 card->channel[0].num=0; 633 card->channel[0].num = 0;
641 return &card->channel[0]; 634 return &card->channel[0];
642} 635}
643 636
644static void cs_free_pcm_channel(struct cs_card *card, int channel) 637static void cs_free_pcm_channel(struct cs_card *card, int channel)
645{ 638{
646 card->channel[channel].state = NULL; 639 card->channel[channel].state = NULL;
647 card->channel[channel].used=0; 640 card->channel[channel].used = 0;
648} 641}
649 642
650/* 643/*
@@ -655,15 +648,15 @@ static void cs_free_pcm_channel(struct cs_card *card, int channel)
655 */ 648 */
656static void cs_set_divisor(struct dmabuf *dmabuf) 649static void cs_set_divisor(struct dmabuf *dmabuf)
657{ 650{
658 if(dmabuf->type == CS_TYPE_DAC) 651 if (dmabuf->type == CS_TYPE_DAC)
659 dmabuf->divisor = 1; 652 dmabuf->divisor = 1;
660 else if( !(dmabuf->fmt & CS_FMT_STEREO) && 653 else if (!(dmabuf->fmt & CS_FMT_STEREO) &&
661 (dmabuf->fmt & CS_FMT_16BIT)) 654 (dmabuf->fmt & CS_FMT_16BIT))
662 dmabuf->divisor = 2; 655 dmabuf->divisor = 2;
663 else if( (dmabuf->fmt & CS_FMT_STEREO) && 656 else if ((dmabuf->fmt & CS_FMT_STEREO) &&
664 !(dmabuf->fmt & CS_FMT_16BIT)) 657 !(dmabuf->fmt & CS_FMT_16BIT))
665 dmabuf->divisor = 2; 658 dmabuf->divisor = 2;
666 else if( !(dmabuf->fmt & CS_FMT_STEREO) && 659 else if (!(dmabuf->fmt & CS_FMT_STEREO) &&
667 !(dmabuf->fmt & CS_FMT_16BIT)) 660 !(dmabuf->fmt & CS_FMT_16BIT))
668 dmabuf->divisor = 4; 661 dmabuf->divisor = 4;
669 else 662 else
@@ -680,13 +673,12 @@ static void cs_set_divisor(struct dmabuf *dmabuf)
680*/ 673*/
681static void cs_mute(struct cs_card *card, int state) 674static void cs_mute(struct cs_card *card, int state)
682{ 675{
683 struct ac97_codec *dev=card->ac97_codec[0]; 676 struct ac97_codec *dev = card->ac97_codec[0];
684 677
685 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO "cs46xx: cs_mute()+ %s\n", 678 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO "cs46xx: cs_mute()+ %s\n",
686 (state == CS_TRUE) ? "Muting" : "UnMuting") ); 679 (state == CS_TRUE) ? "Muting" : "UnMuting"));
687 680
688 if(state == CS_TRUE) 681 if (state == CS_TRUE) {
689 {
690 /* 682 /*
691 * fix pops when powering up on thinkpads 683 * fix pops when powering up on thinkpads
692 */ 684 */
@@ -703,9 +695,7 @@ static void cs_mute(struct cs_card *card, int state)
703 cs_ac97_set(dev, (u8)BA0_AC97_HEADPHONE_VOLUME, 0x8000); 695 cs_ac97_set(dev, (u8)BA0_AC97_HEADPHONE_VOLUME, 0x8000);
704 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME_MONO, 0x8000); 696 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME_MONO, 0x8000);
705 cs_ac97_set(dev, (u8)BA0_AC97_PCM_OUT_VOLUME, 0x8000); 697 cs_ac97_set(dev, (u8)BA0_AC97_PCM_OUT_VOLUME, 0x8000);
706 } 698 } else {
707 else
708 {
709 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME, card->pm.u32AC97_master_volume); 699 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME, card->pm.u32AC97_master_volume);
710 cs_ac97_set(dev, (u8)BA0_AC97_HEADPHONE_VOLUME, card->pm.u32AC97_headphone_volume); 700 cs_ac97_set(dev, (u8)BA0_AC97_HEADPHONE_VOLUME, card->pm.u32AC97_headphone_volume);
711 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME_MONO, card->pm.u32AC97_master_volume_mono); 701 cs_ac97_set(dev, (u8)BA0_AC97_MASTER_VOLUME_MONO, card->pm.u32AC97_master_volume_mono);
@@ -757,7 +747,6 @@ static unsigned int cs_set_dac_rate(struct cs_state * state, unsigned int rate)
757 /* 747 /*
758 * Fill in the SampleRateConverter control block. 748 * Fill in the SampleRateConverter control block.
759 */ 749 */
760
761 spin_lock_irqsave(&state->card->lock, flags); 750 spin_lock_irqsave(&state->card->lock, flags);
762 cs461x_poke(state->card, BA1_PSRC, 751 cs461x_poke(state->card, BA1_PSRC,
763 ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF)); 752 ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF));
@@ -770,7 +759,7 @@ static unsigned int cs_set_dac_rate(struct cs_state * state, unsigned int rate)
770} 759}
771 760
772/* set recording sample rate */ 761/* set recording sample rate */
773static unsigned int cs_set_adc_rate(struct cs_state * state, unsigned int rate) 762static unsigned int cs_set_adc_rate(struct cs_state *state, unsigned int rate)
774{ 763{
775 struct dmabuf *dmabuf = &state->dmabuf; 764 struct dmabuf *dmabuf = &state->dmabuf;
776 struct cs_card *card = state->card; 765 struct cs_card *card = state->card;
@@ -815,7 +804,6 @@ static unsigned int cs_set_adc_rate(struct cs_state * state, unsigned int rate)
815 * dividend:remainder(ulOther / GOF_PER_SEC) 804 * dividend:remainder(ulOther / GOF_PER_SEC)
816 * initialDelay = dividend(((24 * Fs,in) + Fs,out - 1) / Fs,out) 805 * initialDelay = dividend(((24 * Fs,in) + Fs,out - 1) / Fs,out)
817 */ 806 */
818
819 tmp1 = rate << 16; 807 tmp1 = rate << 16;
820 coeffIncr = tmp1 / 48000; 808 coeffIncr = tmp1 / 48000;
821 tmp1 -= coeffIncr * 48000; 809 tmp1 -= coeffIncr * 48000;
@@ -891,7 +879,7 @@ static void cs_play_setup(struct cs_state *state)
891 879
892 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_play_setup()+\n") ); 880 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_play_setup()+\n") );
893 cs461x_poke(card, BA1_PVOL, 0x80008000); 881 cs461x_poke(card, BA1_PVOL, 0x80008000);
894 if(!dmabuf->SGok) 882 if (!dmabuf->SGok)
895 cs461x_poke(card, BA1_PBA, virt_to_bus(dmabuf->pbuf)); 883 cs461x_poke(card, BA1_PBA, virt_to_bus(dmabuf->pbuf));
896 884
897 Count = 4; 885 Count = 4;
@@ -899,16 +887,14 @@ static void cs_play_setup(struct cs_state *state)
899 if ((dmabuf->fmt & CS_FMT_STEREO)) { 887 if ((dmabuf->fmt & CS_FMT_STEREO)) {
900 playFormat &= ~DMA_RQ_C2_AC_MONO_TO_STEREO; 888 playFormat &= ~DMA_RQ_C2_AC_MONO_TO_STEREO;
901 Count *= 2; 889 Count *= 2;
902 } 890 } else
903 else
904 playFormat |= DMA_RQ_C2_AC_MONO_TO_STEREO; 891 playFormat |= DMA_RQ_C2_AC_MONO_TO_STEREO;
905 892
906 if ((dmabuf->fmt & CS_FMT_16BIT)) { 893 if ((dmabuf->fmt & CS_FMT_16BIT)) {
907 playFormat &= ~(DMA_RQ_C2_AC_8_TO_16_BIT 894 playFormat &= ~(DMA_RQ_C2_AC_8_TO_16_BIT
908 | DMA_RQ_C2_AC_SIGNED_CONVERT); 895 | DMA_RQ_C2_AC_SIGNED_CONVERT);
909 Count *= 2; 896 Count *= 2;
910 } 897 } else
911 else
912 playFormat |= (DMA_RQ_C2_AC_8_TO_16_BIT 898 playFormat |= (DMA_RQ_C2_AC_8_TO_16_BIT
913 | DMA_RQ_C2_AC_SIGNED_CONVERT); 899 | DMA_RQ_C2_AC_SIGNED_CONVERT);
914 900
@@ -919,7 +905,6 @@ static void cs_play_setup(struct cs_state *state)
919 cs461x_poke(card, BA1_PDTC, tmp | --Count); 905 cs461x_poke(card, BA1_PDTC, tmp | --Count);
920 906
921 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_play_setup()-\n") ); 907 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_play_setup()-\n") );
922
923} 908}
924 909
925static struct InitStruct 910static struct InitStruct
@@ -944,8 +929,7 @@ static void SetCaptureSPValues(struct cs_card *card)
944{ 929{
945 unsigned i, offset; 930 unsigned i, offset;
946 CS_DBGOUT(CS_FUNCTION, 8, printk("cs46xx: SetCaptureSPValues()+\n") ); 931 CS_DBGOUT(CS_FUNCTION, 8, printk("cs46xx: SetCaptureSPValues()+\n") );
947 for(i=0; i<sizeof(InitArray)/sizeof(struct InitStruct); i++) 932 for (i = 0; i < sizeof(InitArray) / sizeof(struct InitStruct); i++) {
948 {
949 offset = InitArray[i].off*4; /* 8bit to 32bit offset value */ 933 offset = InitArray[i].off*4; /* 8bit to 32bit offset value */
950 cs461x_poke(card, offset, InitArray[i].val ); 934 cs461x_poke(card, offset, InitArray[i].val );
951 } 935 }
@@ -957,8 +941,8 @@ static void cs_rec_setup(struct cs_state *state)
957{ 941{
958 struct cs_card *card = state->card; 942 struct cs_card *card = state->card;
959 struct dmabuf *dmabuf = &state->dmabuf; 943 struct dmabuf *dmabuf = &state->dmabuf;
960 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_rec_setup()+\n") );
961 944
945 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_rec_setup()+\n"));
962 SetCaptureSPValues(card); 946 SetCaptureSPValues(card);
963 947
964 /* 948 /*
@@ -994,14 +978,11 @@ static inline unsigned cs_get_dma_addr(struct cs_state *state)
994 /* 978 /*
995 * granularity is byte boundary, good part. 979 * granularity is byte boundary, good part.
996 */ 980 */
997 if(dmabuf->enable & DAC_RUNNING) 981 if (dmabuf->enable & DAC_RUNNING)
998 {
999 offset = cs461x_peek(state->card, BA1_PBA); 982 offset = cs461x_peek(state->card, BA1_PBA);
1000 }
1001 else /* ADC_RUNNING must be set */ 983 else /* ADC_RUNNING must be set */
1002 {
1003 offset = cs461x_peek(state->card, BA1_CBA); 984 offset = cs461x_peek(state->card, BA1_CBA);
1004 } 985
1005 CS_DBGOUT(CS_PARMS | CS_FUNCTION, 9, 986 CS_DBGOUT(CS_PARMS | CS_FUNCTION, 9,
1006 printk("cs46xx: cs_get_dma_addr() %d\n",offset) ); 987 printk("cs46xx: cs_get_dma_addr() %d\n",offset) );
1007 offset = (u32)bus_to_virt((unsigned long)offset) - (u32)dmabuf->rawbuf; 988 offset = (u32)bus_to_virt((unsigned long)offset) - (u32)dmabuf->rawbuf;
@@ -1015,8 +996,7 @@ static void resync_dma_ptrs(struct cs_state *state)
1015 struct dmabuf *dmabuf; 996 struct dmabuf *dmabuf;
1016 997
1017 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: resync_dma_ptrs()+ \n") ); 998 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: resync_dma_ptrs()+ \n") );
1018 if(state) 999 if (state) {
1019 {
1020 dmabuf = &state->dmabuf; 1000 dmabuf = &state->dmabuf;
1021 dmabuf->hwptr=dmabuf->swptr = 0; 1001 dmabuf->hwptr=dmabuf->swptr = 0;
1022 dmabuf->pringbuf = 0; 1002 dmabuf->pringbuf = 0;
@@ -1149,13 +1129,13 @@ static int alloc_dmabuf(struct cs_state *state)
1149/* 1129/*
1150* check for order within limits, but do not overwrite value. 1130* check for order within limits, but do not overwrite value.
1151*/ 1131*/
1152 if((defaultorder > 1) && (defaultorder < 12)) 1132 if ((defaultorder > 1) && (defaultorder < 12))
1153 df = defaultorder; 1133 df = defaultorder;
1154 else 1134 else
1155 df = 2; 1135 df = 2;
1156 1136
1157 for (order = df; order >= DMABUF_MINORDER; order--) 1137 for (order = df; order >= DMABUF_MINORDER; order--)
1158 if ( (rawbuf = (void *) pci_alloc_consistent( 1138 if ((rawbuf = (void *)pci_alloc_consistent(
1159 card->pci_dev, PAGE_SIZE << order, &dmabuf->dmaaddr))) 1139 card->pci_dev, PAGE_SIZE << order, &dmabuf->dmaaddr)))
1160 break; 1140 break;
1161 if (!rawbuf) { 1141 if (!rawbuf) {
@@ -1181,8 +1161,7 @@ static int alloc_dmabuf(struct cs_state *state)
1181/* 1161/*
1182* only allocate the conversion buffer for the ADC 1162* only allocate the conversion buffer for the ADC
1183*/ 1163*/
1184 if(dmabuf->type == CS_TYPE_DAC) 1164 if (dmabuf->type == CS_TYPE_DAC) {
1185 {
1186 dmabuf->tmpbuff = NULL; 1165 dmabuf->tmpbuff = NULL;
1187 dmabuf->buforder_tmpbuff = 0; 1166 dmabuf->buforder_tmpbuff = 0;
1188 return 0; 1167 return 0;
@@ -1258,8 +1237,7 @@ static int __prog_dmabuf(struct cs_state *state)
1258/* 1237/*
1259 * check for CAPTURE and use only non-sg for initial release 1238 * check for CAPTURE and use only non-sg for initial release
1260 */ 1239 */
1261 if(dmabuf->type == CS_TYPE_ADC) 1240 if (dmabuf->type == CS_TYPE_ADC) {
1262 {
1263 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf() ADC\n")); 1241 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf() ADC\n"));
1264 /* 1242 /*
1265 * add in non-sg support for capture. 1243 * add in non-sg support for capture.
@@ -1313,9 +1291,7 @@ static int __prog_dmabuf(struct cs_state *state)
1313 1291
1314 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- 0 \n")); 1292 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- 0 \n"));
1315 return 0; 1293 return 0;
1316 } 1294 } else if (dmabuf->type == CS_TYPE_DAC) {
1317 else if (dmabuf->type == CS_TYPE_DAC)
1318 {
1319 /* 1295 /*
1320 * Must be DAC 1296 * Must be DAC
1321 */ 1297 */
@@ -1337,8 +1313,7 @@ static int __prog_dmabuf(struct cs_state *state)
1337 allocated_pages = 1 << dmabuf->buforder; 1313 allocated_pages = 1 << dmabuf->buforder;
1338 allocated_bytes = allocated_pages*PAGE_SIZE; 1314 allocated_bytes = allocated_pages*PAGE_SIZE;
1339 1315
1340 if(allocated_pages < 2) 1316 if (allocated_pages < 2) {
1341 {
1342 CS_DBGOUT(CS_FUNCTION, 4, printk( 1317 CS_DBGOUT(CS_FUNCTION, 4, printk(
1343 "cs46xx: prog_dmabuf() Error: allocated_pages too small (%d)\n", 1318 "cs46xx: prog_dmabuf() Error: allocated_pages too small (%d)\n",
1344 (unsigned)allocated_pages)); 1319 (unsigned)allocated_pages));
@@ -1353,14 +1328,14 @@ static int __prog_dmabuf(struct cs_state *state)
1353 1328
1354 /* Set up S/G variables. */ 1329 /* Set up S/G variables. */
1355 *ptmp = virt_to_bus(dmabuf->rawbuf); 1330 *ptmp = virt_to_bus(dmabuf->rawbuf);
1356 *(ptmp+1) = 0x00000008; 1331 *(ptmp + 1) = 0x00000008;
1357 for(tmp1= 1; tmp1 < nSGpages; tmp1++) { 1332 for (tmp1 = 1; tmp1 < nSGpages; tmp1++) {
1358 *(ptmp+2*tmp1) = virt_to_bus( (dmabuf->rawbuf)+4096*tmp1); 1333 *(ptmp + 2 * tmp1) = virt_to_bus((dmabuf->rawbuf) + 4096 * tmp1);
1359 if( tmp1 == nSGpages-1) 1334 if (tmp1 == nSGpages - 1)
1360 tmp2 = 0xbfff0000; 1335 tmp2 = 0xbfff0000;
1361 else 1336 else
1362 tmp2 = 0x80000000+8*(tmp1+1); 1337 tmp2 = 0x80000000 + 8 * (tmp1 + 1);
1363 *(ptmp+2*tmp1+1) = tmp2; 1338 *(ptmp + 2 * tmp1 + 1) = tmp2;
1364 } 1339 }
1365 SGarray[0] = 0x82c0200d; 1340 SGarray[0] = 0x82c0200d;
1366 SGarray[1] = 0xffff0000; 1341 SGarray[1] = 0xffff0000;
@@ -1368,18 +1343,17 @@ static int __prog_dmabuf(struct cs_state *state)
1368 SGarray[3] = 0x00010600; 1343 SGarray[3] = 0x00010600;
1369 SGarray[4] = *(ptmp+2); 1344 SGarray[4] = *(ptmp+2);
1370 SGarray[5] = 0x80000010; 1345 SGarray[5] = 0x80000010;
1371 SGarray[6] = *ptmp; 1346 SGarray[6] = *ptmp;
1372 SGarray[7] = *(ptmp+2); 1347 SGarray[7] = *(ptmp+2);
1373 SGarray[8] = (virt_to_bus(dmabuf->pbuf) & 0xffff000) | 0x10; 1348 SGarray[8] = (virt_to_bus(dmabuf->pbuf) & 0xffff000) | 0x10;
1374 1349
1375 if (dmabuf->SGok) { 1350 if (dmabuf->SGok) {
1376 dmabuf->numfrag = nSGpages; 1351 dmabuf->numfrag = nSGpages;
1377 dmabuf->fragsize = 4096; 1352 dmabuf->fragsize = 4096;
1378 dmabuf->fragsamples = 4096 >> sample_shift[dmabuf->fmt]; 1353 dmabuf->fragsamples = 4096 >> sample_shift[dmabuf->fmt];
1379 dmabuf->fragshift = 12; 1354 dmabuf->fragshift = 12;
1380 dmabuf->dmasize = dmabuf->numfrag*4096; 1355 dmabuf->dmasize = dmabuf->numfrag * 4096;
1381 } 1356 } else {
1382 else {
1383 SGarray[0] = 0xf2c0000f; 1357 SGarray[0] = 0xf2c0000f;
1384 SGarray[1] = 0x00000200; 1358 SGarray[1] = 0x00000200;
1385 SGarray[2] = 0; 1359 SGarray[2] = 0;
@@ -1391,8 +1365,8 @@ static int __prog_dmabuf(struct cs_state *state)
1391 dmabuf->dmasize = 4096; 1365 dmabuf->dmasize = 4096;
1392 dmabuf->fragshift = 11; 1366 dmabuf->fragshift = 11;
1393 } 1367 }
1394 for(tmp1 = 0; tmp1 < sizeof(SGarray)/4; tmp1++) 1368 for (tmp1 = 0; tmp1 < sizeof(SGarray) / 4; tmp1++)
1395 cs461x_poke( state->card, BA1_PDTC+tmp1*4, SGarray[tmp1]); 1369 cs461x_poke(state->card, BA1_PDTC+tmp1 * 4, SGarray[tmp1]);
1396 1370
1397 memset(dmabuf->rawbuf, (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80, 1371 memset(dmabuf->rawbuf, (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80,
1398 dmabuf->dmasize); 1372 dmabuf->dmasize);
@@ -1416,9 +1390,7 @@ static int __prog_dmabuf(struct cs_state *state)
1416 1390
1417 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- \n")); 1391 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- \n"));
1418 return 0; 1392 return 0;
1419 } 1393 } else {
1420 else
1421 {
1422 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- Invalid Type %d\n", 1394 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: prog_dmabuf()- Invalid Type %d\n",
1423 dmabuf->type)); 1395 dmabuf->type));
1424 } 1396 }
@@ -1489,8 +1461,7 @@ static int drain_dac(struct cs_state *state, int nonblock)
1489 } 1461 }
1490 remove_wait_queue(&dmabuf->wait, &wait); 1462 remove_wait_queue(&dmabuf->wait, &wait);
1491 current->state = TASK_RUNNING; 1463 current->state = TASK_RUNNING;
1492 if (signal_pending(current)) 1464 if (signal_pending(current)) {
1493 {
1494 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: drain_dac()- -ERESTARTSYS\n")); 1465 CS_DBGOUT(CS_FUNCTION, 4, printk("cs46xx: drain_dac()- -ERESTARTSYS\n"));
1495 /* 1466 /*
1496 * set to silence and let that clear the fifos. 1467 * set to silence and let that clear the fifos.
@@ -1514,8 +1485,7 @@ static void cs_update_ptr(struct cs_card *card, int wake)
1514 1485
1515 /* error handling and process wake up for ADC */ 1486 /* error handling and process wake up for ADC */
1516 state = card->states[0]; 1487 state = card->states[0];
1517 if(state) 1488 if (state) {
1518 {
1519 dmabuf = &state->dmabuf; 1489 dmabuf = &state->dmabuf;
1520 if (dmabuf->enable & ADC_RUNNING) { 1490 if (dmabuf->enable & ADC_RUNNING) {
1521 /* update hardware pointer */ 1491 /* update hardware pointer */
@@ -1531,12 +1501,10 @@ static void cs_update_ptr(struct cs_card *card, int wake)
1531 if (dmabuf->count > dmabuf->dmasize) 1501 if (dmabuf->count > dmabuf->dmasize)
1532 dmabuf->count = dmabuf->dmasize; 1502 dmabuf->count = dmabuf->dmasize;
1533 1503
1534 if(dmabuf->mapped) 1504 if (dmabuf->mapped) {
1535 {
1536 if (wake && dmabuf->count >= (signed)dmabuf->fragsize) 1505 if (wake && dmabuf->count >= (signed)dmabuf->fragsize)
1537 wake_up(&dmabuf->wait); 1506 wake_up(&dmabuf->wait);
1538 } else 1507 } else {
1539 {
1540 if (wake && dmabuf->count > 0) 1508 if (wake && dmabuf->count > 0)
1541 wake_up(&dmabuf->wait); 1509 wake_up(&dmabuf->wait);
1542 } 1510 }
@@ -1547,8 +1515,7 @@ static void cs_update_ptr(struct cs_card *card, int wake)
1547 * Now the DAC 1515 * Now the DAC
1548 */ 1516 */
1549 state = card->states[1]; 1517 state = card->states[1];
1550 if(state) 1518 if (state) {
1551 {
1552 dmabuf = &state->dmabuf; 1519 dmabuf = &state->dmabuf;
1553 /* error handling and process wake up for DAC */ 1520 /* error handling and process wake up for DAC */
1554 if (dmabuf->enable & DAC_RUNNING) { 1521 if (dmabuf->enable & DAC_RUNNING) {
@@ -1570,7 +1537,7 @@ static void cs_update_ptr(struct cs_card *card, int wake)
1570 * in that, since dmasize is the buffer asked for 1537 * in that, since dmasize is the buffer asked for
1571 * via mmap. 1538 * via mmap.
1572 */ 1539 */
1573 if( dmabuf->count > dmabuf->dmasize) 1540 if (dmabuf->count > dmabuf->dmasize)
1574 dmabuf->count &= dmabuf->dmasize-1; 1541 dmabuf->count &= dmabuf->dmasize-1;
1575 } else { 1542 } else {
1576 dmabuf->count -= diff; 1543 dmabuf->count -= diff;
@@ -1578,13 +1545,10 @@ static void cs_update_ptr(struct cs_card *card, int wake)
1578 * backfill with silence and clear out the last 1545 * backfill with silence and clear out the last
1579 * "diff" number of bytes. 1546 * "diff" number of bytes.
1580 */ 1547 */
1581 if(hwptr >= diff) 1548 if (hwptr >= diff) {
1582 {
1583 memset(dmabuf->rawbuf + hwptr - diff, 1549 memset(dmabuf->rawbuf + hwptr - diff,
1584 (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80, diff); 1550 (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80, diff);
1585 } 1551 } else {
1586 else
1587 {
1588 memset(dmabuf->rawbuf, 1552 memset(dmabuf->rawbuf,
1589 (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80, 1553 (dmabuf->fmt & CS_FMT_16BIT) ? 0 : 0x80,
1590 (unsigned)hwptr); 1554 (unsigned)hwptr);
@@ -1602,12 +1566,12 @@ static void cs_update_ptr(struct cs_card *card, int wake)
1602 * buffer underrun or buffer overrun, reset the 1566 * buffer underrun or buffer overrun, reset the
1603 * count of bytes written back to 0. 1567 * count of bytes written back to 0.
1604 */ 1568 */
1605 if(dmabuf->count < 0) 1569 if (dmabuf->count < 0)
1606 dmabuf->underrun=1; 1570 dmabuf->underrun = 1;
1607 dmabuf->count = 0; 1571 dmabuf->count = 0;
1608 dmabuf->error++; 1572 dmabuf->error++;
1609 } 1573 }
1610 if (wake && dmabuf->count < (signed)dmabuf->dmasize/2) 1574 if (wake && dmabuf->count < (signed)dmabuf->dmasize / 2)
1611 wake_up(&dmabuf->wait); 1575 wake_up(&dmabuf->wait);
1612 } 1576 }
1613 } 1577 }
@@ -1661,8 +1625,7 @@ static irqreturn_t cs_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1661 1625
1662 status = cs461x_peekBA0(card, BA0_HISR); 1626 status = cs461x_peekBA0(card, BA0_HISR);
1663 1627
1664 if ((status & 0x7fffffff) == 0) 1628 if ((status & 0x7fffffff) == 0) {
1665 {
1666 cs461x_pokeBA0(card, BA0_HICR, HICR_CHGM|HICR_IEV); 1629 cs461x_pokeBA0(card, BA0_HICR, HICR_CHGM|HICR_IEV);
1667 spin_unlock(&card->lock); 1630 spin_unlock(&card->lock);
1668 return IRQ_HANDLED; /* Might be IRQ_NONE.. */ 1631 return IRQ_HANDLED; /* Might be IRQ_NONE.. */
@@ -1671,15 +1634,14 @@ static irqreturn_t cs_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1671 /* 1634 /*
1672 * check for playback or capture interrupt only 1635 * check for playback or capture interrupt only
1673 */ 1636 */
1674 if( ((status & HISR_VC0) && playstate && playstate->dmabuf.ready) || 1637 if (((status & HISR_VC0) && playstate && playstate->dmabuf.ready) ||
1675 (((status & HISR_VC1) && recstate && recstate->dmabuf.ready)) ) 1638 (((status & HISR_VC1) && recstate && recstate->dmabuf.ready))) {
1676 {
1677 CS_DBGOUT(CS_INTERRUPT, 8, printk( 1639 CS_DBGOUT(CS_INTERRUPT, 8, printk(
1678 "cs46xx: cs_interrupt() interrupt bit(s) set (0x%x)\n",status)); 1640 "cs46xx: cs_interrupt() interrupt bit(s) set (0x%x)\n",status));
1679 cs_update_ptr(card, CS_TRUE); 1641 cs_update_ptr(card, CS_TRUE);
1680 } 1642 }
1681 1643
1682 if( status & HISR_MIDI ) 1644 if (status & HISR_MIDI)
1683 cs_handle_midi(card); 1645 cs_handle_midi(card);
1684 1646
1685 /* clear 'em */ 1647 /* clear 'em */
@@ -1694,7 +1656,7 @@ static irqreturn_t cs_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1694 1656
1695static ssize_t cs_midi_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) 1657static ssize_t cs_midi_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
1696{ 1658{
1697 struct cs_card *card = (struct cs_card *)file->private_data; 1659 struct cs_card *card = file->private_data;
1698 ssize_t ret; 1660 ssize_t ret;
1699 unsigned long flags; 1661 unsigned long flags;
1700 unsigned ptr; 1662 unsigned ptr;
@@ -1737,7 +1699,7 @@ static ssize_t cs_midi_read(struct file *file, char __user *buffer, size_t count
1737 1699
1738static ssize_t cs_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) 1700static ssize_t cs_midi_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
1739{ 1701{
1740 struct cs_card *card = (struct cs_card *)file->private_data; 1702 struct cs_card *card = file->private_data;
1741 ssize_t ret; 1703 ssize_t ret;
1742 unsigned long flags; 1704 unsigned long flags;
1743 unsigned ptr; 1705 unsigned ptr;
@@ -1785,7 +1747,7 @@ static ssize_t cs_midi_write(struct file *file, const char __user *buffer, size_
1785 1747
1786static unsigned int cs_midi_poll(struct file *file, struct poll_table_struct *wait) 1748static unsigned int cs_midi_poll(struct file *file, struct poll_table_struct *wait)
1787{ 1749{
1788 struct cs_card *card = (struct cs_card *)file->private_data; 1750 struct cs_card *card = file->private_data;
1789 unsigned long flags; 1751 unsigned long flags;
1790 unsigned int mask = 0; 1752 unsigned int mask = 0;
1791 1753
@@ -1810,12 +1772,11 @@ static unsigned int cs_midi_poll(struct file *file, struct poll_table_struct *wa
1810static int cs_midi_open(struct inode *inode, struct file *file) 1772static int cs_midi_open(struct inode *inode, struct file *file)
1811{ 1773{
1812 unsigned int minor = iminor(inode); 1774 unsigned int minor = iminor(inode);
1813 struct cs_card *card=NULL; 1775 struct cs_card *card = NULL;
1814 unsigned long flags; 1776 unsigned long flags;
1815 struct list_head *entry; 1777 struct list_head *entry;
1816 1778
1817 list_for_each(entry, &cs46xx_devs) 1779 list_for_each(entry, &cs46xx_devs) {
1818 {
1819 card = list_entry(entry, struct cs_card, list); 1780 card = list_entry(entry, struct cs_card, list);
1820 if (card->dev_midi == minor) 1781 if (card->dev_midi == minor)
1821 break; 1782 break;
@@ -1823,8 +1784,7 @@ static int cs_midi_open(struct inode *inode, struct file *file)
1823 1784
1824 if (entry == &cs46xx_devs) 1785 if (entry == &cs46xx_devs)
1825 return -ENODEV; 1786 return -ENODEV;
1826 if (!card) 1787 if (!card) {
1827 {
1828 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO 1788 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
1829 "cs46xx: cs46xx_midi_open(): Error - unable to find card struct\n")); 1789 "cs46xx: cs46xx_midi_open(): Error - unable to find card struct\n"));
1830 return -ENODEV; 1790 return -ENODEV;
@@ -1852,12 +1812,10 @@ static int cs_midi_open(struct inode *inode, struct file *file)
1852 cs461x_pokeBA0(card, BA0_MIDCR, 0x0000000f); /* Enable xmit, rcv. */ 1812 cs461x_pokeBA0(card, BA0_MIDCR, 0x0000000f); /* Enable xmit, rcv. */
1853 cs461x_pokeBA0(card, BA0_HICR, HICR_IEV | HICR_CHGM); /* Enable interrupts */ 1813 cs461x_pokeBA0(card, BA0_HICR, HICR_IEV | HICR_CHGM); /* Enable interrupts */
1854 } 1814 }
1855 if (file->f_mode & FMODE_READ) { 1815 if (file->f_mode & FMODE_READ)
1856 card->midi.ird = card->midi.iwr = card->midi.icnt = 0; 1816 card->midi.ird = card->midi.iwr = card->midi.icnt = 0;
1857 } 1817 if (file->f_mode & FMODE_WRITE)
1858 if (file->f_mode & FMODE_WRITE) {
1859 card->midi.ord = card->midi.owr = card->midi.ocnt = 0; 1818 card->midi.ord = card->midi.owr = card->midi.ocnt = 0;
1860 }
1861 spin_unlock_irqrestore(&card->midi.lock, flags); 1819 spin_unlock_irqrestore(&card->midi.lock, flags);
1862 card->midi.open_mode |= (file->f_mode & (FMODE_READ | FMODE_WRITE)); 1820 card->midi.open_mode |= (file->f_mode & (FMODE_READ | FMODE_WRITE));
1863 mutex_unlock(&card->midi.open_mutex); 1821 mutex_unlock(&card->midi.open_mutex);
@@ -1867,7 +1825,7 @@ static int cs_midi_open(struct inode *inode, struct file *file)
1867 1825
1868static int cs_midi_release(struct inode *inode, struct file *file) 1826static int cs_midi_release(struct inode *inode, struct file *file)
1869{ 1827{
1870 struct cs_card *card = (struct cs_card *)file->private_data; 1828 struct cs_card *card = file->private_data;
1871 DECLARE_WAITQUEUE(wait, current); 1829 DECLARE_WAITQUEUE(wait, current);
1872 unsigned long flags; 1830 unsigned long flags;
1873 unsigned count, tmo; 1831 unsigned count, tmo;
@@ -1933,11 +1891,10 @@ static /*const*/ struct file_operations cs_midi_fops = {
1933static void CopySamples(char *dst, char *src, int count, unsigned fmt, 1891static void CopySamples(char *dst, char *src, int count, unsigned fmt,
1934 struct dmabuf *dmabuf) 1892 struct dmabuf *dmabuf)
1935{ 1893{
1936
1937 s32 s32AudioSample; 1894 s32 s32AudioSample;
1938 s16 *psSrc=(s16 *)src; 1895 s16 *psSrc = (s16 *)src;
1939 s16 *psDst=(s16 *)dst; 1896 s16 *psDst = (s16 *)dst;
1940 u8 *pucDst=(u8 *)dst; 1897 u8 *pucDst = (u8 *)dst;
1941 1898
1942 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO "cs46xx: CopySamples()+ ") ); 1899 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO "cs46xx: CopySamples()+ ") );
1943 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO 1900 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
@@ -1947,34 +1904,29 @@ static void CopySamples(char *dst, char *src, int count, unsigned fmt,
1947 /* 1904 /*
1948 * See if the data should be output as 8-bit unsigned stereo. 1905 * See if the data should be output as 8-bit unsigned stereo.
1949 */ 1906 */
1950 if((fmt & CS_FMT_STEREO) && !(fmt & CS_FMT_16BIT)) 1907 if ((fmt & CS_FMT_STEREO) && !(fmt & CS_FMT_16BIT)) {
1951 {
1952 /* 1908 /*
1953 * Convert each 16-bit signed stereo sample to 8-bit unsigned 1909 * Convert each 16-bit signed stereo sample to 8-bit unsigned
1954 * stereo using rounding. 1910 * stereo using rounding.
1955 */ 1911 */
1956 psSrc = (s16 *)src; 1912 psSrc = (s16 *)src;
1957 count = count/2; 1913 count = count / 2;
1958 while(count--) 1914 while (count--)
1959 {
1960 *(pucDst++) = (u8)(((s16)(*psSrc++) + (s16)0x8000) >> 8); 1915 *(pucDst++) = (u8)(((s16)(*psSrc++) + (s16)0x8000) >> 8);
1961 }
1962 } 1916 }
1963 /* 1917 /*
1964 * See if the data should be output at 8-bit unsigned mono. 1918 * See if the data should be output at 8-bit unsigned mono.
1965 */ 1919 */
1966 else if(!(fmt & CS_FMT_STEREO) && !(fmt & CS_FMT_16BIT)) 1920 else if (!(fmt & CS_FMT_STEREO) && !(fmt & CS_FMT_16BIT)) {
1967 {
1968 /* 1921 /*
1969 * Convert each 16-bit signed stereo sample to 8-bit unsigned 1922 * Convert each 16-bit signed stereo sample to 8-bit unsigned
1970 * mono using averaging and rounding. 1923 * mono using averaging and rounding.
1971 */ 1924 */
1972 psSrc = (s16 *)src; 1925 psSrc = (s16 *)src;
1973 count = count/2; 1926 count = count / 2;
1974 while(count--) 1927 while (count--) {
1975 { 1928 s32AudioSample = ((*psSrc) + (*(psSrc + 1))) / 2 + (s32)0x80;
1976 s32AudioSample = ((*psSrc)+(*(psSrc + 1)))/2 + (s32)0x80; 1929 if (s32AudioSample > 0x7fff)
1977 if(s32AudioSample > 0x7fff)
1978 s32AudioSample = 0x7fff; 1930 s32AudioSample = 0x7fff;
1979 *(pucDst++) = (u8)(((s16)s32AudioSample + (s16)0x8000) >> 8); 1931 *(pucDst++) = (u8)(((s16)s32AudioSample + (s16)0x8000) >> 8);
1980 psSrc += 2; 1932 psSrc += 2;
@@ -1983,17 +1935,15 @@ static void CopySamples(char *dst, char *src, int count, unsigned fmt,
1983 /* 1935 /*
1984 * See if the data should be output at 16-bit signed mono. 1936 * See if the data should be output at 16-bit signed mono.
1985 */ 1937 */
1986 else if(!(fmt & CS_FMT_STEREO) && (fmt & CS_FMT_16BIT)) 1938 else if (!(fmt & CS_FMT_STEREO) && (fmt & CS_FMT_16BIT)) {
1987 {
1988 /* 1939 /*
1989 * Convert each 16-bit signed stereo sample to 16-bit signed 1940 * Convert each 16-bit signed stereo sample to 16-bit signed
1990 * mono using averaging. 1941 * mono using averaging.
1991 */ 1942 */
1992 psSrc = (s16 *)src; 1943 psSrc = (s16 *)src;
1993 count = count/2; 1944 count = count / 2;
1994 while(count--) 1945 while (count--) {
1995 { 1946 *(psDst++) = (s16)((*psSrc) + (*(psSrc + 1))) / 2;
1996 *(psDst++) = (s16)((*psSrc)+(*(psSrc + 1)))/2;
1997 psSrc += 2; 1947 psSrc += 2;
1998 } 1948 }
1999 } 1949 }
@@ -2020,20 +1970,15 @@ static unsigned cs_copy_to_user(
2020 "cs_copy_to_user()+ fmt=0x%x cnt=%d dest=%p\n", 1970 "cs_copy_to_user()+ fmt=0x%x cnt=%d dest=%p\n",
2021 dmabuf->fmt,(unsigned)cnt,dest) ); 1971 dmabuf->fmt,(unsigned)cnt,dest) );
2022 1972
2023 if(cnt > dmabuf->dmasize) 1973 if (cnt > dmabuf->dmasize)
2024 {
2025 cnt = dmabuf->dmasize; 1974 cnt = dmabuf->dmasize;
2026 } 1975 if (!cnt) {
2027 if(!cnt)
2028 {
2029 *copied = 0; 1976 *copied = 0;
2030 return 0; 1977 return 0;
2031 } 1978 }
2032 if(dmabuf->divisor != 1) 1979 if (dmabuf->divisor != 1) {
2033 { 1980 if (!dmabuf->tmpbuff) {
2034 if(!dmabuf->tmpbuff) 1981 *copied = cnt / dmabuf->divisor;
2035 {
2036 *copied = cnt/dmabuf->divisor;
2037 return 0; 1982 return 0;
2038 } 1983 }
2039 1984
@@ -2042,17 +1987,16 @@ static unsigned cs_copy_to_user(
2042 src = dmabuf->tmpbuff; 1987 src = dmabuf->tmpbuff;
2043 cnt = cnt/dmabuf->divisor; 1988 cnt = cnt/dmabuf->divisor;
2044 } 1989 }
2045 if (copy_to_user(dest, src, cnt)) 1990 if (copy_to_user(dest, src, cnt)) {
2046 {
2047 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_ERR 1991 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_ERR
2048 "cs46xx: cs_copy_to_user()- fault dest=%p src=%p cnt=%d\n", 1992 "cs46xx: cs_copy_to_user()- fault dest=%p src=%p cnt=%d\n",
2049 dest,src,cnt) ); 1993 dest,src,cnt));
2050 *copied = 0; 1994 *copied = 0;
2051 return -EFAULT; 1995 return -EFAULT;
2052 } 1996 }
2053 *copied = cnt; 1997 *copied = cnt;
2054 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO 1998 CS_DBGOUT(CS_FUNCTION, 2, printk(KERN_INFO
2055 "cs46xx: cs_copy_to_user()- copied bytes is %d \n",cnt) ); 1999 "cs46xx: cs_copy_to_user()- copied bytes is %d \n",cnt));
2056 return 0; 2000 return 0;
2057} 2001}
2058 2002
@@ -2060,7 +2004,7 @@ static unsigned cs_copy_to_user(
2060 the user's buffer. it is filled by the dma machine and drained by this loop. */ 2004 the user's buffer. it is filled by the dma machine and drained by this loop. */
2061static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) 2005static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2062{ 2006{
2063 struct cs_card *card = (struct cs_card *) file->private_data; 2007 struct cs_card *card = file->private_data;
2064 struct cs_state *state; 2008 struct cs_state *state;
2065 DECLARE_WAITQUEUE(wait, current); 2009 DECLARE_WAITQUEUE(wait, current);
2066 struct dmabuf *dmabuf; 2010 struct dmabuf *dmabuf;
@@ -2068,12 +2012,12 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof
2068 unsigned long flags; 2012 unsigned long flags;
2069 unsigned swptr; 2013 unsigned swptr;
2070 int cnt; 2014 int cnt;
2071 unsigned copied=0; 2015 unsigned copied = 0;
2072 2016
2073 CS_DBGOUT(CS_WAVE_READ | CS_FUNCTION, 4, 2017 CS_DBGOUT(CS_WAVE_READ | CS_FUNCTION, 4,
2074 printk("cs46xx: cs_read()+ %zd\n",count) ); 2018 printk("cs46xx: cs_read()+ %zd\n",count) );
2075 state = (struct cs_state *)card->states[0]; 2019 state = card->states[0];
2076 if(!state) 2020 if (!state)
2077 return -ENODEV; 2021 return -ENODEV;
2078 dmabuf = &state->dmabuf; 2022 dmabuf = &state->dmabuf;
2079 2023
@@ -2088,11 +2032,11 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof
2088 2032
2089 add_wait_queue(&state->dmabuf.wait, &wait); 2033 add_wait_queue(&state->dmabuf.wait, &wait);
2090 while (count > 0) { 2034 while (count > 0) {
2091 while(!(card->pm.flags & CS46XX_PM_IDLE)) 2035 while (!(card->pm.flags & CS46XX_PM_IDLE)) {
2092 {
2093 schedule(); 2036 schedule();
2094 if (signal_pending(current)) { 2037 if (signal_pending(current)) {
2095 if(!ret) ret = -ERESTARTSYS; 2038 if (!ret)
2039 ret = -ERESTARTSYS;
2096 goto out; 2040 goto out;
2097 } 2041 }
2098 } 2042 }
@@ -2112,19 +2056,20 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof
2112 recorded */ 2056 recorded */
2113 start_adc(state); 2057 start_adc(state);
2114 if (file->f_flags & O_NONBLOCK) { 2058 if (file->f_flags & O_NONBLOCK) {
2115 if (!ret) ret = -EAGAIN; 2059 if (!ret)
2060 ret = -EAGAIN;
2116 goto out; 2061 goto out;
2117 } 2062 }
2118 mutex_unlock(&state->sem); 2063 mutex_unlock(&state->sem);
2119 schedule(); 2064 schedule();
2120 if (signal_pending(current)) { 2065 if (signal_pending(current)) {
2121 if(!ret) ret = -ERESTARTSYS; 2066 if (!ret)
2067 ret = -ERESTARTSYS;
2122 goto out; 2068 goto out;
2123 } 2069 }
2124 mutex_lock(&state->sem); 2070 mutex_lock(&state->sem);
2125 if (dmabuf->mapped) 2071 if (dmabuf->mapped) {
2126 { 2072 if (!ret)
2127 if(!ret)
2128 ret = -ENXIO; 2073 ret = -ENXIO;
2129 goto out; 2074 goto out;
2130 } 2075 }
@@ -2135,12 +2080,12 @@ static ssize_t cs_read(struct file *file, char __user *buffer, size_t count, lof
2135 "_read() copy_to cnt=%d count=%zd ", cnt,count) ); 2080 "_read() copy_to cnt=%d count=%zd ", cnt,count) );
2136 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO 2081 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
2137 " .dmasize=%d .count=%d buffer=%p ret=%zd\n", 2082 " .dmasize=%d .count=%d buffer=%p ret=%zd\n",
2138 dmabuf->dmasize,dmabuf->count,buffer,ret) ); 2083 dmabuf->dmasize,dmabuf->count,buffer,ret));
2139 2084
2140 if (cs_copy_to_user(state, buffer, 2085 if (cs_copy_to_user(state, buffer,
2141 (char *)dmabuf->rawbuf + swptr, cnt, &copied)) 2086 (char *)dmabuf->rawbuf + swptr, cnt, &copied)) {
2142 { 2087 if (!ret)
2143 if (!ret) ret = -EFAULT; 2088 ret = -EFAULT;
2144 goto out; 2089 goto out;
2145 } 2090 }
2146 swptr = (swptr + cnt) % dmabuf->dmasize; 2091 swptr = (swptr + cnt) % dmabuf->dmasize;
@@ -2167,7 +2112,7 @@ out2:
2167 the soundcard. it is drained by the dma machine and filled by this loop. */ 2112 the soundcard. it is drained by the dma machine and filled by this loop. */
2168static ssize_t cs_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) 2113static ssize_t cs_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
2169{ 2114{
2170 struct cs_card *card = (struct cs_card *) file->private_data; 2115 struct cs_card *card = file->private_data;
2171 struct cs_state *state; 2116 struct cs_state *state;
2172 DECLARE_WAITQUEUE(wait, current); 2117 DECLARE_WAITQUEUE(wait, current);
2173 struct dmabuf *dmabuf; 2118 struct dmabuf *dmabuf;
@@ -2178,16 +2123,15 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou
2178 2123
2179 CS_DBGOUT(CS_WAVE_WRITE | CS_FUNCTION, 4, 2124 CS_DBGOUT(CS_WAVE_WRITE | CS_FUNCTION, 4,
2180 printk("cs46xx: cs_write called, count = %zd\n", count) ); 2125 printk("cs46xx: cs_write called, count = %zd\n", count) );
2181 state = (struct cs_state *)card->states[1]; 2126 state = card->states[1];
2182 if(!state) 2127 if (!state)
2183 return -ENODEV; 2128 return -ENODEV;
2184 if (!access_ok(VERIFY_READ, buffer, count)) 2129 if (!access_ok(VERIFY_READ, buffer, count))
2185 return -EFAULT; 2130 return -EFAULT;
2186 dmabuf = &state->dmabuf; 2131 dmabuf = &state->dmabuf;
2187 2132
2188 mutex_lock(&state->sem); 2133 mutex_lock(&state->sem);
2189 if (dmabuf->mapped) 2134 if (dmabuf->mapped) {
2190 {
2191 ret = -ENXIO; 2135 ret = -ENXIO;
2192 goto out; 2136 goto out;
2193 } 2137 }
@@ -2201,11 +2145,11 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou
2201* check for PM events and underrun/overrun in the loop. 2145* check for PM events and underrun/overrun in the loop.
2202*/ 2146*/
2203 while (count > 0) { 2147 while (count > 0) {
2204 while(!(card->pm.flags & CS46XX_PM_IDLE)) 2148 while (!(card->pm.flags & CS46XX_PM_IDLE)) {
2205 {
2206 schedule(); 2149 schedule();
2207 if (signal_pending(current)) { 2150 if (signal_pending(current)) {
2208 if(!ret) ret = -ERESTARTSYS; 2151 if (!ret)
2152 ret = -ERESTARTSYS;
2209 goto out; 2153 goto out;
2210 } 2154 }
2211 } 2155 }
@@ -2216,8 +2160,7 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou
2216 dmabuf->count = 0; 2160 dmabuf->count = 0;
2217 dmabuf->swptr = dmabuf->hwptr; 2161 dmabuf->swptr = dmabuf->hwptr;
2218 } 2162 }
2219 if (dmabuf->underrun) 2163 if (dmabuf->underrun) {
2220 {
2221 dmabuf->underrun = 0; 2164 dmabuf->underrun = 0;
2222 dmabuf->hwptr = cs_get_dma_addr(state); 2165 dmabuf->hwptr = cs_get_dma_addr(state);
2223 dmabuf->swptr = dmabuf->hwptr; 2166 dmabuf->swptr = dmabuf->hwptr;
@@ -2238,34 +2181,35 @@ static ssize_t cs_write(struct file *file, const char __user *buffer, size_t cou
2238 played */ 2181 played */
2239 start_dac(state); 2182 start_dac(state);
2240 if (file->f_flags & O_NONBLOCK) { 2183 if (file->f_flags & O_NONBLOCK) {
2241 if (!ret) ret = -EAGAIN; 2184 if (!ret)
2185 ret = -EAGAIN;
2242 goto out; 2186 goto out;
2243 } 2187 }
2244 mutex_unlock(&state->sem); 2188 mutex_unlock(&state->sem);
2245 schedule(); 2189 schedule();
2246 if (signal_pending(current)) { 2190 if (signal_pending(current)) {
2247 if(!ret) ret = -ERESTARTSYS; 2191 if (!ret)
2192 ret = -ERESTARTSYS;
2248 goto out; 2193 goto out;
2249 } 2194 }
2250 mutex_lock(&state->sem); 2195 mutex_lock(&state->sem);
2251 if (dmabuf->mapped) 2196 if (dmabuf->mapped) {
2252 { 2197 if (!ret)
2253 if(!ret)
2254 ret = -ENXIO; 2198 ret = -ENXIO;
2255 goto out; 2199 goto out;
2256 } 2200 }
2257 continue; 2201 continue;
2258 } 2202 }
2259 if (copy_from_user(dmabuf->rawbuf + swptr, buffer, cnt)) { 2203 if (copy_from_user(dmabuf->rawbuf + swptr, buffer, cnt)) {
2260 if (!ret) ret = -EFAULT; 2204 if (!ret)
2205 ret = -EFAULT;
2261 goto out; 2206 goto out;
2262 } 2207 }
2263 spin_lock_irqsave(&state->card->lock, flags); 2208 spin_lock_irqsave(&state->card->lock, flags);
2264 swptr = (swptr + cnt) % dmabuf->dmasize; 2209 swptr = (swptr + cnt) % dmabuf->dmasize;
2265 dmabuf->swptr = swptr; 2210 dmabuf->swptr = swptr;
2266 dmabuf->count += cnt; 2211 dmabuf->count += cnt;
2267 if(dmabuf->count > dmabuf->dmasize) 2212 if (dmabuf->count > dmabuf->dmasize) {
2268 {
2269 CS_DBGOUT(CS_WAVE_WRITE | CS_ERROR, 2, printk( 2213 CS_DBGOUT(CS_WAVE_WRITE | CS_ERROR, 2, printk(
2270 "cs46xx: cs_write() d->count > dmasize - resetting\n")); 2214 "cs46xx: cs_write() d->count > dmasize - resetting\n"));
2271 dmabuf->count = dmabuf->dmasize; 2215 dmabuf->count = dmabuf->dmasize;
@@ -2284,38 +2228,32 @@ out:
2284 set_current_state(TASK_RUNNING); 2228 set_current_state(TASK_RUNNING);
2285 2229
2286 CS_DBGOUT(CS_WAVE_WRITE | CS_FUNCTION, 2, 2230 CS_DBGOUT(CS_WAVE_WRITE | CS_FUNCTION, 2,
2287 printk("cs46xx: cs_write()- ret=%zd\n", ret) ); 2231 printk("cs46xx: cs_write()- ret=%zd\n", ret));
2288 return ret; 2232 return ret;
2289} 2233}
2290 2234
2291static unsigned int cs_poll(struct file *file, struct poll_table_struct *wait) 2235static unsigned int cs_poll(struct file *file, struct poll_table_struct *wait)
2292{ 2236{
2293 struct cs_card *card = (struct cs_card *)file->private_data; 2237 struct cs_card *card = file->private_data;
2294 struct dmabuf *dmabuf; 2238 struct dmabuf *dmabuf;
2295 struct cs_state *state; 2239 struct cs_state *state;
2296
2297 unsigned long flags; 2240 unsigned long flags;
2298 unsigned int mask = 0; 2241 unsigned int mask = 0;
2299 2242
2300 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_poll()+ \n")); 2243 CS_DBGOUT(CS_FUNCTION, 2, printk("cs46xx: cs_poll()+ \n"));
2301 if (!(file->f_mode & (FMODE_WRITE | FMODE_READ))) 2244 if (!(file->f_mode & (FMODE_WRITE | FMODE_READ))) {
2302 {
2303 return -EINVAL; 2245 return -EINVAL;
2304 } 2246 }
2305 if (file->f_mode & FMODE_WRITE) 2247 if (file->f_mode & FMODE_WRITE) {
2306 {
2307 state = card->states[1]; 2248 state = card->states[1];
2308 if(state) 2249 if (state) {
2309 {
2310 dmabuf = &state->dmabuf; 2250 dmabuf = &state->dmabuf;
2311 poll_wait(file, &dmabuf->wait, wait); 2251 poll_wait(file, &dmabuf->wait, wait);
2312 } 2252 }
2313 } 2253 }
2314 if (file->f_mode & FMODE_READ) 2254 if (file->f_mode & FMODE_READ) {
2315 {
2316 state = card->states[0]; 2255 state = card->states[0];
2317 if(state) 2256 if (state) {
2318 {
2319 dmabuf = &state->dmabuf; 2257 dmabuf = &state->dmabuf;
2320 poll_wait(file, &dmabuf->wait, wait); 2258 poll_wait(file, &dmabuf->wait, wait);
2321 } 2259 }
@@ -2325,8 +2263,7 @@ static unsigned int cs_poll(struct file *file, struct poll_table_struct *wait)
2325 cs_update_ptr(card, CS_FALSE); 2263 cs_update_ptr(card, CS_FALSE);
2326 if (file->f_mode & FMODE_READ) { 2264 if (file->f_mode & FMODE_READ) {
2327 state = card->states[0]; 2265 state = card->states[0];
2328 if(state) 2266 if (state) {
2329 {
2330 dmabuf = &state->dmabuf; 2267 dmabuf = &state->dmabuf;
2331 if (dmabuf->count >= (signed)dmabuf->fragsize) 2268 if (dmabuf->count >= (signed)dmabuf->fragsize)
2332 mask |= POLLIN | POLLRDNORM; 2269 mask |= POLLIN | POLLRDNORM;
@@ -2334,8 +2271,7 @@ static unsigned int cs_poll(struct file *file, struct poll_table_struct *wait)
2334 } 2271 }
2335 if (file->f_mode & FMODE_WRITE) { 2272 if (file->f_mode & FMODE_WRITE) {
2336 state = card->states[1]; 2273 state = card->states[1];
2337 if(state) 2274 if (state) {
2338 {
2339 dmabuf = &state->dmabuf; 2275 dmabuf = &state->dmabuf;
2340 if (dmabuf->mapped) { 2276 if (dmabuf->mapped) {
2341 if (dmabuf->count >= (signed)dmabuf->fragsize) 2277 if (dmabuf->count >= (signed)dmabuf->fragsize)
@@ -2364,7 +2300,7 @@ static unsigned int cs_poll(struct file *file, struct poll_table_struct *wait)
2364 2300
2365static int cs_mmap(struct file *file, struct vm_area_struct *vma) 2301static int cs_mmap(struct file *file, struct vm_area_struct *vma)
2366{ 2302{
2367 struct cs_card *card = (struct cs_card *)file->private_data; 2303 struct cs_card *card = file->private_data;
2368 struct cs_state *state; 2304 struct cs_state *state;
2369 struct dmabuf *dmabuf; 2305 struct dmabuf *dmabuf;
2370 int ret = 0; 2306 int ret = 0;
@@ -2376,8 +2312,7 @@ static int cs_mmap(struct file *file, struct vm_area_struct *vma)
2376 2312
2377 if (vma->vm_flags & VM_WRITE) { 2313 if (vma->vm_flags & VM_WRITE) {
2378 state = card->states[1]; 2314 state = card->states[1];
2379 if(state) 2315 if (state) {
2380 {
2381 CS_DBGOUT(CS_OPEN, 2, printk( 2316 CS_DBGOUT(CS_OPEN, 2, printk(
2382 "cs46xx: cs_mmap() VM_WRITE - state TRUE prog_dmabuf DAC\n") ); 2317 "cs46xx: cs_mmap() VM_WRITE - state TRUE prog_dmabuf DAC\n") );
2383 if ((ret = prog_dmabuf(state)) != 0) 2318 if ((ret = prog_dmabuf(state)) != 0)
@@ -2385,8 +2320,7 @@ static int cs_mmap(struct file *file, struct vm_area_struct *vma)
2385 } 2320 }
2386 } else if (vma->vm_flags & VM_READ) { 2321 } else if (vma->vm_flags & VM_READ) {
2387 state = card->states[0]; 2322 state = card->states[0];
2388 if(state) 2323 if (state) {
2389 {
2390 CS_DBGOUT(CS_OPEN, 2, printk( 2324 CS_DBGOUT(CS_OPEN, 2, printk(
2391 "cs46xx: cs_mmap() VM_READ - state TRUE prog_dmabuf ADC\n") ); 2325 "cs46xx: cs_mmap() VM_READ - state TRUE prog_dmabuf ADC\n") );
2392 if ((ret = prog_dmabuf(state)) != 0) 2326 if ((ret = prog_dmabuf(state)) != 0)
@@ -2414,8 +2348,7 @@ static int cs_mmap(struct file *file, struct vm_area_struct *vma)
2414 2348
2415 mutex_lock(&state->sem); 2349 mutex_lock(&state->sem);
2416 dmabuf = &state->dmabuf; 2350 dmabuf = &state->dmabuf;
2417 if (cs4x_pgoff(vma) != 0) 2351 if (cs4x_pgoff(vma) != 0) {
2418 {
2419 ret = -EINVAL; 2352 ret = -EINVAL;
2420 goto out; 2353 goto out;
2421 } 2354 }
@@ -2423,15 +2356,13 @@ static int cs_mmap(struct file *file, struct vm_area_struct *vma)
2423 2356
2424 CS_DBGOUT(CS_PARMS, 2, printk("cs46xx: cs_mmap(): size=%d\n",(unsigned)size) ); 2357 CS_DBGOUT(CS_PARMS, 2, printk("cs46xx: cs_mmap(): size=%d\n",(unsigned)size) );
2425 2358
2426 if (size > (PAGE_SIZE << dmabuf->buforder)) 2359 if (size > (PAGE_SIZE << dmabuf->buforder)) {
2427 {
2428 ret = -EINVAL; 2360 ret = -EINVAL;
2429 goto out; 2361 goto out;
2430 } 2362 }
2431 if (remap_pfn_range(vma, vma->vm_start, 2363 if (remap_pfn_range(vma, vma->vm_start,
2432 virt_to_phys(dmabuf->rawbuf) >> PAGE_SHIFT, 2364 virt_to_phys(dmabuf->rawbuf) >> PAGE_SHIFT,
2433 size, vma->vm_page_prot)) 2365 size, vma->vm_page_prot)) {
2434 {
2435 ret = -EAGAIN; 2366 ret = -EAGAIN;
2436 goto out; 2367 goto out;
2437 } 2368 }
@@ -2445,25 +2376,24 @@ out:
2445 2376
2446static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 2377static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
2447{ 2378{
2448 struct cs_card *card = (struct cs_card *)file->private_data; 2379 struct cs_card *card = file->private_data;
2449 struct cs_state *state; 2380 struct cs_state *state;
2450 struct dmabuf *dmabuf=NULL; 2381 struct dmabuf *dmabuf = NULL;
2451 unsigned long flags; 2382 unsigned long flags;
2452 audio_buf_info abinfo; 2383 audio_buf_info abinfo;
2453 count_info cinfo; 2384 count_info cinfo;
2454 int val, valsave, mapped, ret; 2385 int val, valsave, ret;
2386 int mapped = 0;
2455 void __user *argp = (void __user *)arg; 2387 void __user *argp = (void __user *)arg;
2456 int __user *p = argp; 2388 int __user *p = argp;
2457 2389
2458 state = (struct cs_state *)card->states[0]; 2390 state = card->states[0];
2459 if(state) 2391 if (state) {
2460 {
2461 dmabuf = &state->dmabuf; 2392 dmabuf = &state->dmabuf;
2462 mapped = (file->f_mode & FMODE_READ) && dmabuf->mapped; 2393 mapped = (file->f_mode & FMODE_READ) && dmabuf->mapped;
2463 } 2394 }
2464 state = (struct cs_state *)card->states[1]; 2395 state = card->states[1];
2465 if(state) 2396 if (state) {
2466 {
2467 dmabuf = &state->dmabuf; 2397 dmabuf = &state->dmabuf;
2468 mapped |= (file->f_mode & FMODE_WRITE) && dmabuf->mapped; 2398 mapped |= (file->f_mode & FMODE_WRITE) && dmabuf->mapped;
2469 } 2399 }
@@ -2472,17 +2402,14 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2472 printioctl(cmd); 2402 printioctl(cmd);
2473#endif 2403#endif
2474 2404
2475 switch (cmd) 2405 switch (cmd) {
2476 {
2477 case OSS_GETVERSION: 2406 case OSS_GETVERSION:
2478 return put_user(SOUND_VERSION, p); 2407 return put_user(SOUND_VERSION, p);
2479
2480 case SNDCTL_DSP_RESET: 2408 case SNDCTL_DSP_RESET:
2481 /* FIXME: spin_lock ? */ 2409 /* FIXME: spin_lock ? */
2482 if (file->f_mode & FMODE_WRITE) { 2410 if (file->f_mode & FMODE_WRITE) {
2483 state = (struct cs_state *)card->states[1]; 2411 state = card->states[1];
2484 if(state) 2412 if (state) {
2485 {
2486 dmabuf = &state->dmabuf; 2413 dmabuf = &state->dmabuf;
2487 stop_dac(state); 2414 stop_dac(state);
2488 synchronize_irq(card->irq); 2415 synchronize_irq(card->irq);
@@ -2495,9 +2422,8 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2495 } 2422 }
2496 } 2423 }
2497 if (file->f_mode & FMODE_READ) { 2424 if (file->f_mode & FMODE_READ) {
2498 state = (struct cs_state *)card->states[0]; 2425 state = card->states[0];
2499 if(state) 2426 if (state) {
2500 {
2501 dmabuf = &state->dmabuf; 2427 dmabuf = &state->dmabuf;
2502 stop_adc(state); 2428 stop_adc(state);
2503 synchronize_irq(card->irq); 2429 synchronize_irq(card->irq);
@@ -2511,20 +2437,17 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2511 } 2437 }
2512 CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_RESET()-\n") ); 2438 CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_RESET()-\n") );
2513 return 0; 2439 return 0;
2514
2515 case SNDCTL_DSP_SYNC: 2440 case SNDCTL_DSP_SYNC:
2516 if (file->f_mode & FMODE_WRITE) 2441 if (file->f_mode & FMODE_WRITE)
2517 return drain_dac(state, file->f_flags & O_NONBLOCK); 2442 return drain_dac(state, file->f_flags & O_NONBLOCK);
2518 return 0; 2443 return 0;
2519
2520 case SNDCTL_DSP_SPEED: /* set sample rate */ 2444 case SNDCTL_DSP_SPEED: /* set sample rate */
2521 if (get_user(val, p)) 2445 if (get_user(val, p))
2522 return -EFAULT; 2446 return -EFAULT;
2523 if (val >= 0) { 2447 if (val >= 0) {
2524 if (file->f_mode & FMODE_READ) { 2448 if (file->f_mode & FMODE_READ) {
2525 state = (struct cs_state *)card->states[0]; 2449 state = card->states[0];
2526 if(state) 2450 if (state) {
2527 {
2528 dmabuf = &state->dmabuf; 2451 dmabuf = &state->dmabuf;
2529 stop_adc(state); 2452 stop_adc(state);
2530 dmabuf->ready = 0; 2453 dmabuf->ready = 0;
@@ -2534,9 +2457,8 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2534 } 2457 }
2535 } 2458 }
2536 if (file->f_mode & FMODE_WRITE) { 2459 if (file->f_mode & FMODE_WRITE) {
2537 state = (struct cs_state *)card->states[1]; 2460 state = card->states[1];
2538 if(state) 2461 if (state) {
2539 {
2540 dmabuf = &state->dmabuf; 2462 dmabuf = &state->dmabuf;
2541 stop_dac(state); 2463 stop_dac(state);
2542 dmabuf->ready = 0; 2464 dmabuf->ready = 0;
@@ -2553,19 +2475,17 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2553 return put_user(dmabuf->rate, p); 2475 return put_user(dmabuf->rate, p);
2554 } 2476 }
2555 return put_user(0, p); 2477 return put_user(0, p);
2556
2557 case SNDCTL_DSP_STEREO: /* set stereo or mono channel */ 2478 case SNDCTL_DSP_STEREO: /* set stereo or mono channel */
2558 if (get_user(val, p)) 2479 if (get_user(val, p))
2559 return -EFAULT; 2480 return -EFAULT;
2560 if (file->f_mode & FMODE_WRITE) { 2481 if (file->f_mode & FMODE_WRITE) {
2561 state = (struct cs_state *)card->states[1]; 2482 state = card->states[1];
2562 if(state) 2483 if (state) {
2563 {
2564 dmabuf = &state->dmabuf; 2484 dmabuf = &state->dmabuf;
2565 stop_dac(state); 2485 stop_dac(state);
2566 dmabuf->ready = 0; 2486 dmabuf->ready = 0;
2567 dmabuf->SGok = 0; 2487 dmabuf->SGok = 0;
2568 if(val) 2488 if (val)
2569 dmabuf->fmt |= CS_FMT_STEREO; 2489 dmabuf->fmt |= CS_FMT_STEREO;
2570 else 2490 else
2571 dmabuf->fmt &= ~CS_FMT_STEREO; 2491 dmabuf->fmt &= ~CS_FMT_STEREO;
@@ -2577,14 +2497,13 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2577 } 2497 }
2578 } 2498 }
2579 if (file->f_mode & FMODE_READ) { 2499 if (file->f_mode & FMODE_READ) {
2580 state = (struct cs_state *)card->states[0]; 2500 state = card->states[0];
2581 if(state) 2501 if (state) {
2582 {
2583 dmabuf = &state->dmabuf; 2502 dmabuf = &state->dmabuf;
2584 stop_adc(state); 2503 stop_adc(state);
2585 dmabuf->ready = 0; 2504 dmabuf->ready = 0;
2586 dmabuf->SGok = 0; 2505 dmabuf->SGok = 0;
2587 if(val) 2506 if (val)
2588 dmabuf->fmt |= CS_FMT_STEREO; 2507 dmabuf->fmt |= CS_FMT_STEREO;
2589 else 2508 else
2590 dmabuf->fmt &= ~CS_FMT_STEREO; 2509 dmabuf->fmt &= ~CS_FMT_STEREO;
@@ -2596,12 +2515,10 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2596 } 2515 }
2597 } 2516 }
2598 return 0; 2517 return 0;
2599
2600 case SNDCTL_DSP_GETBLKSIZE: 2518 case SNDCTL_DSP_GETBLKSIZE:
2601 if (file->f_mode & FMODE_WRITE) { 2519 if (file->f_mode & FMODE_WRITE) {
2602 state = (struct cs_state *)card->states[1]; 2520 state = card->states[1];
2603 if(state) 2521 if (state) {
2604 {
2605 dmabuf = &state->dmabuf; 2522 dmabuf = &state->dmabuf;
2606 if ((val = prog_dmabuf(state))) 2523 if ((val = prog_dmabuf(state)))
2607 return val; 2524 return val;
@@ -2609,9 +2526,8 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2609 } 2526 }
2610 } 2527 }
2611 if (file->f_mode & FMODE_READ) { 2528 if (file->f_mode & FMODE_READ) {
2612 state = (struct cs_state *)card->states[0]; 2529 state = card->states[0];
2613 if(state) 2530 if (state) {
2614 {
2615 dmabuf = &state->dmabuf; 2531 dmabuf = &state->dmabuf;
2616 if ((val = prog_dmabuf(state))) 2532 if ((val = prog_dmabuf(state)))
2617 return val; 2533 return val;
@@ -2620,10 +2536,8 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2620 } 2536 }
2621 } 2537 }
2622 return put_user(0, p); 2538 return put_user(0, p);
2623
2624 case SNDCTL_DSP_GETFMTS: /* Returns a mask of supported sample format*/ 2539 case SNDCTL_DSP_GETFMTS: /* Returns a mask of supported sample format*/
2625 return put_user(AFMT_S16_LE | AFMT_U8, p); 2540 return put_user(AFMT_S16_LE | AFMT_U8, p);
2626
2627 case SNDCTL_DSP_SETFMT: /* Select sample format */ 2541 case SNDCTL_DSP_SETFMT: /* Select sample format */
2628 if (get_user(val, p)) 2542 if (get_user(val, p))
2629 return -EFAULT; 2543 return -EFAULT;
@@ -2635,88 +2549,75 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2635 val == AFMT_U8 ? "8Bit Unsigned" : "") ); 2549 val == AFMT_U8 ? "8Bit Unsigned" : "") );
2636 valsave = val; 2550 valsave = val;
2637 if (val != AFMT_QUERY) { 2551 if (val != AFMT_QUERY) {
2638 if(val==AFMT_S16_LE || val==AFMT_U8) 2552 if (val==AFMT_S16_LE || val==AFMT_U8) {
2639 {
2640 if (file->f_mode & FMODE_WRITE) { 2553 if (file->f_mode & FMODE_WRITE) {
2641 state = (struct cs_state *)card->states[1]; 2554 state = card->states[1];
2642 if(state) 2555 if (state) {
2643 {
2644 dmabuf = &state->dmabuf; 2556 dmabuf = &state->dmabuf;
2645 stop_dac(state); 2557 stop_dac(state);
2646 dmabuf->ready = 0; 2558 dmabuf->ready = 0;
2647 dmabuf->SGok = 0; 2559 dmabuf->SGok = 0;
2648 if(val==AFMT_S16_LE) 2560 if (val == AFMT_S16_LE)
2649 dmabuf->fmt |= CS_FMT_16BIT; 2561 dmabuf->fmt |= CS_FMT_16BIT;
2650 else 2562 else
2651 dmabuf->fmt &= ~CS_FMT_16BIT; 2563 dmabuf->fmt &= ~CS_FMT_16BIT;
2652 cs_set_divisor(dmabuf); 2564 cs_set_divisor(dmabuf);
2653 if((ret = prog_dmabuf(state))) 2565 if ((ret = prog_dmabuf(state)))
2654 return ret; 2566 return ret;
2655 } 2567 }
2656 } 2568 }
2657 if (file->f_mode & FMODE_READ) { 2569 if (file->f_mode & FMODE_READ) {
2658 val = valsave; 2570 val = valsave;
2659 state = (struct cs_state *)card->states[0]; 2571 state = card->states[0];
2660 if(state) 2572 if (state) {
2661 {
2662 dmabuf = &state->dmabuf; 2573 dmabuf = &state->dmabuf;
2663 stop_adc(state); 2574 stop_adc(state);
2664 dmabuf->ready = 0; 2575 dmabuf->ready = 0;
2665 dmabuf->SGok = 0; 2576 dmabuf->SGok = 0;
2666 if(val==AFMT_S16_LE) 2577 if (val == AFMT_S16_LE)
2667 dmabuf->fmt |= CS_FMT_16BIT; 2578 dmabuf->fmt |= CS_FMT_16BIT;
2668 else 2579 else
2669 dmabuf->fmt &= ~CS_FMT_16BIT; 2580 dmabuf->fmt &= ~CS_FMT_16BIT;
2670 cs_set_divisor(dmabuf); 2581 cs_set_divisor(dmabuf);
2671 if((ret = prog_dmabuf(state))) 2582 if ((ret = prog_dmabuf(state)))
2672 return ret; 2583 return ret;
2673 } 2584 }
2674 } 2585 }
2675 } 2586 } else {
2676 else
2677 {
2678 CS_DBGOUT(CS_IOCTL | CS_ERROR, 2, printk( 2587 CS_DBGOUT(CS_IOCTL | CS_ERROR, 2, printk(
2679 "cs46xx: DSP_SETFMT() Unsupported format (0x%x)\n", 2588 "cs46xx: DSP_SETFMT() Unsupported format (0x%x)\n",
2680 valsave) ); 2589 valsave) );
2681 } 2590 }
2682 } 2591 } else {
2683 else 2592 if (file->f_mode & FMODE_WRITE) {
2684 { 2593 state = card->states[1];
2685 if(file->f_mode & FMODE_WRITE) 2594 if (state)
2686 {
2687 state = (struct cs_state *)card->states[1];
2688 if(state)
2689 dmabuf = &state->dmabuf; 2595 dmabuf = &state->dmabuf;
2690 } 2596 } else if (file->f_mode & FMODE_READ) {
2691 else if(file->f_mode & FMODE_READ) 2597 state = card->states[0];
2692 { 2598 if (state)
2693 state = (struct cs_state *)card->states[0];
2694 if(state)
2695 dmabuf = &state->dmabuf; 2599 dmabuf = &state->dmabuf;
2696 } 2600 }
2697 } 2601 }
2698 if(dmabuf) 2602 if (dmabuf) {
2699 { 2603 if (dmabuf->fmt & CS_FMT_16BIT)
2700 if(dmabuf->fmt & CS_FMT_16BIT)
2701 return put_user(AFMT_S16_LE, p); 2604 return put_user(AFMT_S16_LE, p);
2702 else 2605 else
2703 return put_user(AFMT_U8, p); 2606 return put_user(AFMT_U8, p);
2704 } 2607 }
2705 return put_user(0, p); 2608 return put_user(0, p);
2706
2707 case SNDCTL_DSP_CHANNELS: 2609 case SNDCTL_DSP_CHANNELS:
2708 if (get_user(val, p)) 2610 if (get_user(val, p))
2709 return -EFAULT; 2611 return -EFAULT;
2710 if (val != 0) { 2612 if (val != 0) {
2711 if (file->f_mode & FMODE_WRITE) { 2613 if (file->f_mode & FMODE_WRITE) {
2712 state = (struct cs_state *)card->states[1]; 2614 state = card->states[1];
2713 if(state) 2615 if (state) {
2714 {
2715 dmabuf = &state->dmabuf; 2616 dmabuf = &state->dmabuf;
2716 stop_dac(state); 2617 stop_dac(state);
2717 dmabuf->ready = 0; 2618 dmabuf->ready = 0;
2718 dmabuf->SGok = 0; 2619 dmabuf->SGok = 0;
2719 if(val>1) 2620 if (val > 1)
2720 dmabuf->fmt |= CS_FMT_STEREO; 2621 dmabuf->fmt |= CS_FMT_STEREO;
2721 else 2622 else
2722 dmabuf->fmt &= ~CS_FMT_STEREO; 2623 dmabuf->fmt &= ~CS_FMT_STEREO;
@@ -2726,14 +2627,13 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2726 } 2627 }
2727 } 2628 }
2728 if (file->f_mode & FMODE_READ) { 2629 if (file->f_mode & FMODE_READ) {
2729 state = (struct cs_state *)card->states[0]; 2630 state = card->states[0];
2730 if(state) 2631 if (state) {
2731 {
2732 dmabuf = &state->dmabuf; 2632 dmabuf = &state->dmabuf;
2733 stop_adc(state); 2633 stop_adc(state);
2734 dmabuf->ready = 0; 2634 dmabuf->ready = 0;
2735 dmabuf->SGok = 0; 2635 dmabuf->SGok = 0;
2736 if(val>1) 2636 if (val > 1)
2737 dmabuf->fmt |= CS_FMT_STEREO; 2637 dmabuf->fmt |= CS_FMT_STEREO;
2738 else 2638 else
2739 dmabuf->fmt &= ~CS_FMT_STEREO; 2639 dmabuf->fmt &= ~CS_FMT_STEREO;
@@ -2745,19 +2645,16 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2745 } 2645 }
2746 return put_user((dmabuf->fmt & CS_FMT_STEREO) ? 2 : 1, 2646 return put_user((dmabuf->fmt & CS_FMT_STEREO) ? 2 : 1,
2747 p); 2647 p);
2748
2749 case SNDCTL_DSP_POST: 2648 case SNDCTL_DSP_POST:
2750 /* 2649 /*
2751 * There will be a longer than normal pause in the data. 2650 * There will be a longer than normal pause in the data.
2752 * so... do nothing, because there is nothing that we can do. 2651 * so... do nothing, because there is nothing that we can do.
2753 */ 2652 */
2754 return 0; 2653 return 0;
2755
2756 case SNDCTL_DSP_SUBDIVIDE: 2654 case SNDCTL_DSP_SUBDIVIDE:
2757 if (file->f_mode & FMODE_WRITE) { 2655 if (file->f_mode & FMODE_WRITE) {
2758 state = (struct cs_state *)card->states[1]; 2656 state = card->states[1];
2759 if(state) 2657 if (state) {
2760 {
2761 dmabuf = &state->dmabuf; 2658 dmabuf = &state->dmabuf;
2762 if (dmabuf->subdivision) 2659 if (dmabuf->subdivision)
2763 return -EINVAL; 2660 return -EINVAL;
@@ -2769,9 +2666,8 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2769 } 2666 }
2770 } 2667 }
2771 if (file->f_mode & FMODE_READ) { 2668 if (file->f_mode & FMODE_READ) {
2772 state = (struct cs_state *)card->states[0]; 2669 state = card->states[0];
2773 if(state) 2670 if (state) {
2774 {
2775 dmabuf = &state->dmabuf; 2671 dmabuf = &state->dmabuf;
2776 if (dmabuf->subdivision) 2672 if (dmabuf->subdivision)
2777 return -EINVAL; 2673 return -EINVAL;
@@ -2783,37 +2679,31 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2783 } 2679 }
2784 } 2680 }
2785 return 0; 2681 return 0;
2786
2787 case SNDCTL_DSP_SETFRAGMENT: 2682 case SNDCTL_DSP_SETFRAGMENT:
2788 if (get_user(val, p)) 2683 if (get_user(val, p))
2789 return -EFAULT; 2684 return -EFAULT;
2790
2791 if (file->f_mode & FMODE_WRITE) { 2685 if (file->f_mode & FMODE_WRITE) {
2792 state = (struct cs_state *)card->states[1]; 2686 state = card->states[1];
2793 if(state) 2687 if (state) {
2794 {
2795 dmabuf = &state->dmabuf; 2688 dmabuf = &state->dmabuf;
2796 dmabuf->ossfragshift = val & 0xffff; 2689 dmabuf->ossfragshift = val & 0xffff;
2797 dmabuf->ossmaxfrags = (val >> 16) & 0xffff; 2690 dmabuf->ossmaxfrags = (val >> 16) & 0xffff;
2798 } 2691 }
2799 } 2692 }
2800 if (file->f_mode & FMODE_READ) { 2693 if (file->f_mode & FMODE_READ) {
2801 state = (struct cs_state *)card->states[0]; 2694 state = card->states[0];
2802 if(state) 2695 if (state) {
2803 {
2804 dmabuf = &state->dmabuf; 2696 dmabuf = &state->dmabuf;
2805 dmabuf->ossfragshift = val & 0xffff; 2697 dmabuf->ossfragshift = val & 0xffff;
2806 dmabuf->ossmaxfrags = (val >> 16) & 0xffff; 2698 dmabuf->ossmaxfrags = (val >> 16) & 0xffff;
2807 } 2699 }
2808 } 2700 }
2809 return 0; 2701 return 0;
2810
2811 case SNDCTL_DSP_GETOSPACE: 2702 case SNDCTL_DSP_GETOSPACE:
2812 if (!(file->f_mode & FMODE_WRITE)) 2703 if (!(file->f_mode & FMODE_WRITE))
2813 return -EINVAL; 2704 return -EINVAL;
2814 state = (struct cs_state *)card->states[1]; 2705 state = card->states[1];
2815 if(state) 2706 if (state) {
2816 {
2817 dmabuf = &state->dmabuf; 2707 dmabuf = &state->dmabuf;
2818 spin_lock_irqsave(&state->card->lock, flags); 2708 spin_lock_irqsave(&state->card->lock, flags);
2819 cs_update_ptr(card, CS_TRUE); 2709 cs_update_ptr(card, CS_TRUE);
@@ -2832,13 +2722,11 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2832 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0; 2722 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2833 } 2723 }
2834 return -ENODEV; 2724 return -ENODEV;
2835
2836 case SNDCTL_DSP_GETISPACE: 2725 case SNDCTL_DSP_GETISPACE:
2837 if (!(file->f_mode & FMODE_READ)) 2726 if (!(file->f_mode & FMODE_READ))
2838 return -EINVAL; 2727 return -EINVAL;
2839 state = (struct cs_state *)card->states[0]; 2728 state = card->states[0];
2840 if(state) 2729 if (state) {
2841 {
2842 dmabuf = &state->dmabuf; 2730 dmabuf = &state->dmabuf;
2843 spin_lock_irqsave(&state->card->lock, flags); 2731 spin_lock_irqsave(&state->card->lock, flags);
2844 cs_update_ptr(card, CS_TRUE); 2732 cs_update_ptr(card, CS_TRUE);
@@ -2850,48 +2738,39 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2850 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0; 2738 return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
2851 } 2739 }
2852 return -ENODEV; 2740 return -ENODEV;
2853
2854 case SNDCTL_DSP_NONBLOCK: 2741 case SNDCTL_DSP_NONBLOCK:
2855 file->f_flags |= O_NONBLOCK; 2742 file->f_flags |= O_NONBLOCK;
2856 return 0; 2743 return 0;
2857
2858 case SNDCTL_DSP_GETCAPS: 2744 case SNDCTL_DSP_GETCAPS:
2859 return put_user(DSP_CAP_REALTIME|DSP_CAP_TRIGGER|DSP_CAP_MMAP, 2745 return put_user(DSP_CAP_REALTIME|DSP_CAP_TRIGGER|DSP_CAP_MMAP,
2860 p); 2746 p);
2861
2862 case SNDCTL_DSP_GETTRIGGER: 2747 case SNDCTL_DSP_GETTRIGGER:
2863 val = 0; 2748 val = 0;
2864 CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_GETTRIGGER()+\n") ); 2749 CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_GETTRIGGER()+\n") );
2865 if (file->f_mode & FMODE_WRITE) 2750 if (file->f_mode & FMODE_WRITE) {
2866 { 2751 state = card->states[1];
2867 state = (struct cs_state *)card->states[1]; 2752 if (state) {
2868 if(state)
2869 {
2870 dmabuf = &state->dmabuf; 2753 dmabuf = &state->dmabuf;
2871 if(dmabuf->enable & DAC_RUNNING) 2754 if (dmabuf->enable & DAC_RUNNING)
2872 val |= PCM_ENABLE_INPUT; 2755 val |= PCM_ENABLE_INPUT;
2873 } 2756 }
2874 } 2757 }
2875 if (file->f_mode & FMODE_READ) 2758 if (file->f_mode & FMODE_READ) {
2876 { 2759 if (state) {
2877 if(state) 2760 state = card->states[0];
2878 {
2879 state = (struct cs_state *)card->states[0];
2880 dmabuf = &state->dmabuf; 2761 dmabuf = &state->dmabuf;
2881 if(dmabuf->enable & ADC_RUNNING) 2762 if (dmabuf->enable & ADC_RUNNING)
2882 val |= PCM_ENABLE_OUTPUT; 2763 val |= PCM_ENABLE_OUTPUT;
2883 } 2764 }
2884 } 2765 }
2885 CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_GETTRIGGER()- val=0x%x\n",val) ); 2766 CS_DBGOUT(CS_IOCTL, 2, printk("cs46xx: DSP_GETTRIGGER()- val=0x%x\n",val) );
2886 return put_user(val, p); 2767 return put_user(val, p);
2887
2888 case SNDCTL_DSP_SETTRIGGER: 2768 case SNDCTL_DSP_SETTRIGGER:
2889 if (get_user(val, p)) 2769 if (get_user(val, p))
2890 return -EFAULT; 2770 return -EFAULT;
2891 if (file->f_mode & FMODE_READ) { 2771 if (file->f_mode & FMODE_READ) {
2892 state = (struct cs_state *)card->states[0]; 2772 state = card->states[0];
2893 if(state) 2773 if (state) {
2894 {
2895 dmabuf = &state->dmabuf; 2774 dmabuf = &state->dmabuf;
2896 if (val & PCM_ENABLE_INPUT) { 2775 if (val & PCM_ENABLE_INPUT) {
2897 if (!dmabuf->ready && (ret = prog_dmabuf(state))) 2776 if (!dmabuf->ready && (ret = prog_dmabuf(state)))
@@ -2902,9 +2781,8 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2902 } 2781 }
2903 } 2782 }
2904 if (file->f_mode & FMODE_WRITE) { 2783 if (file->f_mode & FMODE_WRITE) {
2905 state = (struct cs_state *)card->states[1]; 2784 state = card->states[1];
2906 if(state) 2785 if (state) {
2907 {
2908 dmabuf = &state->dmabuf; 2786 dmabuf = &state->dmabuf;
2909 if (val & PCM_ENABLE_OUTPUT) { 2787 if (val & PCM_ENABLE_OUTPUT) {
2910 if (!dmabuf->ready && (ret = prog_dmabuf(state))) 2788 if (!dmabuf->ready && (ret = prog_dmabuf(state)))
@@ -2915,13 +2793,11 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2915 } 2793 }
2916 } 2794 }
2917 return 0; 2795 return 0;
2918
2919 case SNDCTL_DSP_GETIPTR: 2796 case SNDCTL_DSP_GETIPTR:
2920 if (!(file->f_mode & FMODE_READ)) 2797 if (!(file->f_mode & FMODE_READ))
2921 return -EINVAL; 2798 return -EINVAL;
2922 state = (struct cs_state *)card->states[0]; 2799 state = card->states[0];
2923 if(state) 2800 if (state) {
2924 {
2925 dmabuf = &state->dmabuf; 2801 dmabuf = &state->dmabuf;
2926 spin_lock_irqsave(&state->card->lock, flags); 2802 spin_lock_irqsave(&state->card->lock, flags);
2927 cs_update_ptr(card, CS_TRUE); 2803 cs_update_ptr(card, CS_TRUE);
@@ -2934,28 +2810,23 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2934 return 0; 2810 return 0;
2935 } 2811 }
2936 return -ENODEV; 2812 return -ENODEV;
2937
2938 case SNDCTL_DSP_GETOPTR: 2813 case SNDCTL_DSP_GETOPTR:
2939 if (!(file->f_mode & FMODE_WRITE)) 2814 if (!(file->f_mode & FMODE_WRITE))
2940 return -EINVAL; 2815 return -EINVAL;
2941 state = (struct cs_state *)card->states[1]; 2816 state = card->states[1];
2942 if(state) 2817 if (state) {
2943 {
2944 dmabuf = &state->dmabuf; 2818 dmabuf = &state->dmabuf;
2945 spin_lock_irqsave(&state->card->lock, flags); 2819 spin_lock_irqsave(&state->card->lock, flags);
2946 cs_update_ptr(card, CS_TRUE); 2820 cs_update_ptr(card, CS_TRUE);
2947 cinfo.bytes = dmabuf->total_bytes; 2821 cinfo.bytes = dmabuf->total_bytes;
2948 if (dmabuf->mapped) 2822 if (dmabuf->mapped) {
2949 {
2950 cinfo.blocks = (cinfo.bytes >> dmabuf->fragshift) 2823 cinfo.blocks = (cinfo.bytes >> dmabuf->fragshift)
2951 - dmabuf->blocks; 2824 - dmabuf->blocks;
2952 CS_DBGOUT(CS_PARMS, 8, 2825 CS_DBGOUT(CS_PARMS, 8,
2953 printk("total_bytes=%d blocks=%d dmabuf->blocks=%d\n", 2826 printk("total_bytes=%d blocks=%d dmabuf->blocks=%d\n",
2954 cinfo.bytes,cinfo.blocks,dmabuf->blocks) ); 2827 cinfo.bytes,cinfo.blocks,dmabuf->blocks) );
2955 dmabuf->blocks = cinfo.bytes >> dmabuf->fragshift; 2828 dmabuf->blocks = cinfo.bytes >> dmabuf->fragshift;
2956 } 2829 } else {
2957 else
2958 {
2959 cinfo.blocks = dmabuf->count >> dmabuf->fragshift; 2830 cinfo.blocks = dmabuf->count >> dmabuf->fragshift;
2960 } 2831 }
2961 cinfo.ptr = dmabuf->hwptr; 2832 cinfo.ptr = dmabuf->hwptr;
@@ -2969,66 +2840,54 @@ static int cs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
2969 return 0; 2840 return 0;
2970 } 2841 }
2971 return -ENODEV; 2842 return -ENODEV;
2972
2973 case SNDCTL_DSP_SETDUPLEX: 2843 case SNDCTL_DSP_SETDUPLEX:
2974 return 0; 2844 return 0;
2975
2976 case SNDCTL_DSP_GETODELAY: 2845 case SNDCTL_DSP_GETODELAY:
2977 if (!(file->f_mode & FMODE_WRITE)) 2846 if (!(file->f_mode & FMODE_WRITE))
2978 return -EINVAL; 2847 return -EINVAL;
2979 state = (struct cs_state *)card->states[1]; 2848 state = card->states[1];
2980 if(state) 2849 if (state) {
2981 {
2982 dmabuf = &state->dmabuf; 2850 dmabuf = &state->dmabuf;
2983 spin_lock_irqsave(&state->card->lock, flags); 2851 spin_lock_irqsave(&state->card->lock, flags);
2984 cs_update_ptr(card, CS_TRUE); 2852 cs_update_ptr(card, CS_TRUE);
2985 val = dmabuf->count; 2853 val = dmabuf->count;
2986 spin_unlock_irqrestore(&state->card->lock, flags); 2854 spin_unlock_irqrestore(&state->card->lock, flags);
2987 } 2855 } else
2988 else
2989 val = 0; 2856 val = 0;
2990 return put_user(val, p); 2857 return put_user(val, p);
2991
2992 case SOUND_PCM_READ_RATE: 2858 case SOUND_PCM_READ_RATE:
2993 if(file->f_mode & FMODE_READ) 2859 if (file->f_mode & FMODE_READ)
2994 state = (struct cs_state *)card->states[0]; 2860 state = card->states[0];
2995 else 2861 else
2996 state = (struct cs_state *)card->states[1]; 2862 state = card->states[1];
2997 if(state) 2863 if (state) {
2998 {
2999 dmabuf = &state->dmabuf; 2864 dmabuf = &state->dmabuf;
3000 return put_user(dmabuf->rate, p); 2865 return put_user(dmabuf->rate, p);
3001 } 2866 }
3002 return put_user(0, p); 2867 return put_user(0, p);
3003
3004
3005 case SOUND_PCM_READ_CHANNELS: 2868 case SOUND_PCM_READ_CHANNELS:
3006 if(file->f_mode & FMODE_READ) 2869 if (file->f_mode & FMODE_READ)
3007 state = (struct cs_state *)card->states[0]; 2870 state = card->states[0];
3008 else 2871 else
3009 state = (struct cs_state *)card->states[1]; 2872 state = card->states[1];
3010 if(state) 2873 if (state) {
3011 {
3012 dmabuf = &state->dmabuf; 2874 dmabuf = &state->dmabuf;
3013 return put_user((dmabuf->fmt & CS_FMT_STEREO) ? 2 : 1, 2875 return put_user((dmabuf->fmt & CS_FMT_STEREO) ? 2 : 1,
3014 p); 2876 p);
3015 } 2877 }
3016 return put_user(0, p); 2878 return put_user(0, p);
3017
3018 case SOUND_PCM_READ_BITS: 2879 case SOUND_PCM_READ_BITS:
3019 if(file->f_mode & FMODE_READ) 2880 if (file->f_mode & FMODE_READ)
3020 state = (struct cs_state *)card->states[0]; 2881 state = card->states[0];
3021 else 2882 else
3022 state = (struct cs_state *)card->states[1]; 2883 state = card->states[1];
3023 if(state) 2884 if (state) {
3024 {
3025 dmabuf = &state->dmabuf; 2885 dmabuf = &state->dmabuf;
3026 return put_user((dmabuf->fmt & CS_FMT_16BIT) ? 2886 return put_user((dmabuf->fmt & CS_FMT_16BIT) ?
3027 AFMT_S16_LE : AFMT_U8, p); 2887 AFMT_S16_LE : AFMT_U8, p);
3028 2888
3029 } 2889 }
3030 return put_user(0, p); 2890 return put_user(0, p);
3031
3032 case SNDCTL_DSP_MAPINBUF: 2891 case SNDCTL_DSP_MAPINBUF:
3033 case SNDCTL_DSP_MAPOUTBUF: 2892 case SNDCTL_DSP_MAPOUTBUF:
3034 case SNDCTL_DSP_SETSYNCRO: 2893 case SNDCTL_DSP_SETSYNCRO:
@@ -3057,18 +2916,15 @@ static void amp_voyetra(struct cs_card *card, int change)
3057 /* Manage the EAPD bit on the Crystal 4297 2916 /* Manage the EAPD bit on the Crystal 4297
3058 and the Analog AD1885 */ 2917 and the Analog AD1885 */
3059 2918
3060 int old=card->amplifier; 2919 int old = card->amplifier;
3061 2920
3062 card->amplifier+=change; 2921 card->amplifier+=change;
3063 if(card->amplifier && !old) 2922 if (card->amplifier && !old) {
3064 {
3065 /* Turn the EAPD amp on */ 2923 /* Turn the EAPD amp on */
3066 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, 2924 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL,
3067 cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) | 2925 cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) |
3068 0x8000); 2926 0x8000);
3069 } 2927 } else if(old && !card->amplifier) {
3070 else if(old && !card->amplifier)
3071 {
3072 /* Turn the EAPD amp off */ 2928 /* Turn the EAPD amp off */
3073 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, 2929 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL,
3074 cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) & 2930 cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
@@ -3083,25 +2939,21 @@ static void amp_voyetra(struct cs_card *card, int change)
3083 2939
3084static void amp_hercules(struct cs_card *card, int change) 2940static void amp_hercules(struct cs_card *card, int change)
3085{ 2941{
3086 int old=card->amplifier; 2942 int old = card->amplifier;
3087 if(!card) 2943 if (!card) {
3088 {
3089 CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO 2944 CS_DBGOUT(CS_ERROR, 2, printk(KERN_INFO
3090 "cs46xx: amp_hercules() called before initialized.\n")); 2945 "cs46xx: amp_hercules() called before initialized.\n"));
3091 return; 2946 return;
3092 } 2947 }
3093 card->amplifier+=change; 2948 card->amplifier+=change;
3094 if( (card->amplifier && !old) && !(hercules_egpio_disable)) 2949 if ((card->amplifier && !old) && !(hercules_egpio_disable)) {
3095 {
3096 CS_DBGOUT(CS_PARMS, 4, printk(KERN_INFO 2950 CS_DBGOUT(CS_PARMS, 4, printk(KERN_INFO
3097 "cs46xx: amp_hercules() external amp enabled\n")); 2951 "cs46xx: amp_hercules() external amp enabled\n"));
3098 cs461x_pokeBA0(card, BA0_EGPIODR, 2952 cs461x_pokeBA0(card, BA0_EGPIODR,
3099 EGPIODR_GPOE2); /* enable EGPIO2 output */ 2953 EGPIODR_GPOE2); /* enable EGPIO2 output */
3100 cs461x_pokeBA0(card, BA0_EGPIOPTR, 2954 cs461x_pokeBA0(card, BA0_EGPIOPTR,
3101 EGPIOPTR_GPPT2); /* open-drain on output */ 2955 EGPIOPTR_GPPT2); /* open-drain on output */
3102 } 2956 } else if (old && !card->amplifier) {
3103 else if(old && !card->amplifier)
3104 {
3105 CS_DBGOUT(CS_PARMS, 4, printk(KERN_INFO 2957 CS_DBGOUT(CS_PARMS, 4, printk(KERN_INFO
3106 "cs46xx: amp_hercules() external amp disabled\n")); 2958 "cs46xx: amp_hercules() external amp disabled\n"));
3107 cs461x_pokeBA0(card, BA0_EGPIODR, 0); /* disable */ 2959 cs461x_pokeBA0(card, BA0_EGPIODR, 0); /* disable */
@@ -3124,31 +2976,28 @@ static void clkrun_hack(struct cs_card *card, int change)
3124 u16 control; 2976 u16 control;
3125 u8 pp; 2977 u8 pp;
3126 unsigned long port; 2978 unsigned long port;
3127 int old=card->active; 2979 int old = card->active;
3128 2980
3129 card->active+=change; 2981 card->active+=change;
3130 2982
3131 acpi_dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, NULL); 2983 acpi_dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
3132 if(acpi_dev == NULL) 2984 if (acpi_dev == NULL)
3133 return; /* Not a thinkpad thats for sure */ 2985 return; /* Not a thinkpad thats for sure */
3134 2986
3135 /* Find the control port */ 2987 /* Find the control port */
3136 pci_read_config_byte(acpi_dev, 0x41, &pp); 2988 pci_read_config_byte(acpi_dev, 0x41, &pp);
3137 port=pp<<8; 2989 port = pp << 8;
3138 2990
3139 /* Read ACPI port */ 2991 /* Read ACPI port */
3140 control=inw(port+0x10); 2992 control = inw(port + 0x10);
3141 2993
3142 /* Flip CLKRUN off while running */ 2994 /* Flip CLKRUN off while running */
3143 if(!card->active && old) 2995 if (!card->active && old) {
3144 {
3145 CS_DBGOUT(CS_PARMS , 9, printk( KERN_INFO 2996 CS_DBGOUT(CS_PARMS , 9, printk( KERN_INFO
3146 "cs46xx: clkrun() enable clkrun - change=%d active=%d\n", 2997 "cs46xx: clkrun() enable clkrun - change=%d active=%d\n",
3147 change,card->active)); 2998 change,card->active));
3148 outw(control|0x2000, port+0x10); 2999 outw(control|0x2000, port+0x10);
3149 } 3000 } else {
3150 else
3151 {
3152 /* 3001 /*
3153 * sometimes on a resume the bit is set, so always reset the bit. 3002 * sometimes on a resume the bit is set, so always reset the bit.
3154 */ 3003 */
@@ -3162,20 +3011,19 @@ static void clkrun_hack(struct cs_card *card, int change)
3162 3011
3163static int cs_open(struct inode *inode, struct file *file) 3012static int cs_open(struct inode *inode, struct file *file)
3164{ 3013{
3165 struct cs_card *card = (struct cs_card *)file->private_data; 3014 struct cs_card *card = file->private_data;
3166 struct cs_state *state = NULL; 3015 struct cs_state *state = NULL;
3167 struct dmabuf *dmabuf = NULL; 3016 struct dmabuf *dmabuf = NULL;
3168 struct list_head *entry; 3017 struct list_head *entry;
3169 unsigned int minor = iminor(inode); 3018 unsigned int minor = iminor(inode);
3170 int ret=0; 3019 int ret = 0;
3171 unsigned int tmp; 3020 unsigned int tmp;
3172 3021
3173 CS_DBGOUT(CS_OPEN | CS_FUNCTION, 2, printk("cs46xx: cs_open()+ file=%p %s %s\n", 3022 CS_DBGOUT(CS_OPEN | CS_FUNCTION, 2, printk("cs46xx: cs_open()+ file=%p %s %s\n",
3174 file, file->f_mode & FMODE_WRITE ? "FMODE_WRITE" : "", 3023 file, file->f_mode & FMODE_WRITE ? "FMODE_WRITE" : "",
3175 file->f_mode & FMODE_READ ? "FMODE_READ" : "") ); 3024 file->f_mode & FMODE_READ ? "FMODE_READ" : "") );
3176 3025
3177 list_for_each(entry, &cs46xx_devs) 3026 list_for_each(entry, &cs46xx_devs) {
3178 {
3179 card = list_entry(entry, struct cs_card, list); 3027 card = list_entry(entry, struct cs_card, list);
3180 3028
3181 if (!((card->dev_audio ^ minor) & ~0xf)) 3029 if (!((card->dev_audio ^ minor) & ~0xf))
@@ -3192,11 +3040,10 @@ static int cs_open(struct inode *inode, struct file *file)
3192 /* 3040 /*
3193 * hardcode state[0] for capture, [1] for playback 3041 * hardcode state[0] for capture, [1] for playback
3194 */ 3042 */
3195 if(file->f_mode & FMODE_READ) 3043 if (file->f_mode & FMODE_READ) {
3196 {
3197 CS_DBGOUT(CS_WAVE_READ, 2, printk("cs46xx: cs_open() FMODE_READ\n") ); 3044 CS_DBGOUT(CS_WAVE_READ, 2, printk("cs46xx: cs_open() FMODE_READ\n") );
3198 if (card->states[0] == NULL) { 3045 if (card->states[0] == NULL) {
3199 state = card->states[0] = (struct cs_state *) 3046 state = card->states[0] =
3200 kmalloc(sizeof(struct cs_state), GFP_KERNEL); 3047 kmalloc(sizeof(struct cs_state), GFP_KERNEL);
3201 if (state == NULL) 3048 if (state == NULL)
3202 return -ENOMEM; 3049 return -ENOMEM;
@@ -3204,36 +3051,32 @@ static int cs_open(struct inode *inode, struct file *file)
3204 mutex_init(&state->sem); 3051 mutex_init(&state->sem);
3205 dmabuf = &state->dmabuf; 3052 dmabuf = &state->dmabuf;
3206 dmabuf->pbuf = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); 3053 dmabuf->pbuf = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
3207 if(dmabuf->pbuf==NULL) 3054 if (dmabuf->pbuf == NULL) {
3208 {
3209 kfree(state); 3055 kfree(state);
3210 card->states[0]=NULL; 3056 card->states[0] = NULL;
3211 return -ENOMEM; 3057 return -ENOMEM;
3212 } 3058 }
3213 } 3059 } else {
3214 else
3215 {
3216 state = card->states[0]; 3060 state = card->states[0];
3217 if(state->open_mode & FMODE_READ) 3061 if (state->open_mode & FMODE_READ)
3218 return -EBUSY; 3062 return -EBUSY;
3219 } 3063 }
3220 dmabuf->channel = card->alloc_rec_pcm_channel(card); 3064 dmabuf->channel = card->alloc_rec_pcm_channel(card);
3221 3065
3222 if (dmabuf->channel == NULL) { 3066 if (dmabuf->channel == NULL) {
3223 kfree (card->states[0]); 3067 kfree(card->states[0]);
3224 card->states[0] = NULL; 3068 card->states[0] = NULL;
3225 return -ENODEV; 3069 return -ENODEV;
3226 } 3070 }
3227 3071
3228 /* Now turn on external AMP if needed */ 3072 /* Now turn on external AMP if needed */
3229 state->card = card; 3073 state->card = card;
3230 state->card->active_ctrl(state->card,1); 3074 state->card->active_ctrl(state->card, 1);
3231 state->card->amplifier_ctrl(state->card,1); 3075 state->card->amplifier_ctrl(state->card, 1);
3232 3076
3233 if( (tmp = cs46xx_powerup(card, CS_POWER_ADC)) ) 3077 if ((tmp = cs46xx_powerup(card, CS_POWER_ADC))) {
3234 {
3235 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO 3078 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
3236 "cs46xx: cs46xx_powerup of ADC failed (0x%x)\n",tmp) ); 3079 "cs46xx: cs46xx_powerup of ADC failed (0x%x)\n", tmp));
3237 return -EIO; 3080 return -EIO;
3238 } 3081 }
3239 3082
@@ -3263,11 +3106,10 @@ static int cs_open(struct inode *inode, struct file *file)
3263 state->open_mode |= FMODE_READ; 3106 state->open_mode |= FMODE_READ;
3264 mutex_unlock(&state->open_mutex); 3107 mutex_unlock(&state->open_mutex);
3265 } 3108 }
3266 if(file->f_mode & FMODE_WRITE) 3109 if (file->f_mode & FMODE_WRITE) {
3267 {
3268 CS_DBGOUT(CS_OPEN, 2, printk("cs46xx: cs_open() FMODE_WRITE\n") ); 3110 CS_DBGOUT(CS_OPEN, 2, printk("cs46xx: cs_open() FMODE_WRITE\n") );
3269 if (card->states[1] == NULL) { 3111 if (card->states[1] == NULL) {
3270 state = card->states[1] = (struct cs_state *) 3112 state = card->states[1] =
3271 kmalloc(sizeof(struct cs_state), GFP_KERNEL); 3113 kmalloc(sizeof(struct cs_state), GFP_KERNEL);
3272 if (state == NULL) 3114 if (state == NULL)
3273 return -ENOMEM; 3115 return -ENOMEM;
@@ -3275,36 +3117,32 @@ static int cs_open(struct inode *inode, struct file *file)
3275 mutex_init(&state->sem); 3117 mutex_init(&state->sem);
3276 dmabuf = &state->dmabuf; 3118 dmabuf = &state->dmabuf;
3277 dmabuf->pbuf = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); 3119 dmabuf->pbuf = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
3278 if(dmabuf->pbuf==NULL) 3120 if (dmabuf->pbuf == NULL) {
3279 {
3280 kfree(state); 3121 kfree(state);
3281 card->states[1]=NULL; 3122 card->states[1] = NULL;
3282 return -ENOMEM; 3123 return -ENOMEM;
3283 } 3124 }
3284 } 3125 } else {
3285 else
3286 {
3287 state = card->states[1]; 3126 state = card->states[1];
3288 if(state->open_mode & FMODE_WRITE) 3127 if (state->open_mode & FMODE_WRITE)
3289 return -EBUSY; 3128 return -EBUSY;
3290 } 3129 }
3291 dmabuf->channel = card->alloc_pcm_channel(card); 3130 dmabuf->channel = card->alloc_pcm_channel(card);
3292 3131
3293 if (dmabuf->channel == NULL) { 3132 if (dmabuf->channel == NULL) {
3294 kfree (card->states[1]); 3133 kfree(card->states[1]);
3295 card->states[1] = NULL; 3134 card->states[1] = NULL;
3296 return -ENODEV; 3135 return -ENODEV;
3297 } 3136 }
3298 3137
3299 /* Now turn on external AMP if needed */ 3138 /* Now turn on external AMP if needed */
3300 state->card = card; 3139 state->card = card;
3301 state->card->active_ctrl(state->card,1); 3140 state->card->active_ctrl(state->card, 1);
3302 state->card->amplifier_ctrl(state->card,1); 3141 state->card->amplifier_ctrl(state->card, 1);
3303 3142
3304 if( (tmp = cs46xx_powerup(card, CS_POWER_DAC)) ) 3143 if ((tmp = cs46xx_powerup(card, CS_POWER_DAC))) {
3305 {
3306 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO 3144 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
3307 "cs46xx: cs46xx_powerup of DAC failed (0x%x)\n",tmp) ); 3145 "cs46xx: cs46xx_powerup of DAC failed (0x%x)\n", tmp));
3308 return -EIO; 3146 return -EIO;
3309 } 3147 }
3310 3148
@@ -3333,33 +3171,29 @@ static int cs_open(struct inode *inode, struct file *file)
3333 3171
3334 state->open_mode |= FMODE_WRITE; 3172 state->open_mode |= FMODE_WRITE;
3335 mutex_unlock(&state->open_mutex); 3173 mutex_unlock(&state->open_mutex);
3336 if((ret = prog_dmabuf(state))) 3174 if ((ret = prog_dmabuf(state)))
3337 return ret; 3175 return ret;
3338 } 3176 }
3339 CS_DBGOUT(CS_OPEN | CS_FUNCTION, 2, printk("cs46xx: cs_open()- 0\n") ); 3177 CS_DBGOUT(CS_OPEN | CS_FUNCTION, 2, printk("cs46xx: cs_open()- 0\n"));
3340 return nonseekable_open(inode, file); 3178 return nonseekable_open(inode, file);
3341} 3179}
3342 3180
3343static int cs_release(struct inode *inode, struct file *file) 3181static int cs_release(struct inode *inode, struct file *file)
3344{ 3182{
3345 struct cs_card *card = (struct cs_card *)file->private_data; 3183 struct cs_card *card = file->private_data;
3346 struct dmabuf *dmabuf; 3184 struct dmabuf *dmabuf;
3347 struct cs_state *state; 3185 struct cs_state *state;
3348 unsigned int tmp; 3186 unsigned int tmp;
3349 CS_DBGOUT(CS_RELEASE | CS_FUNCTION, 2, printk("cs46xx: cs_release()+ file=%p %s %s\n", 3187 CS_DBGOUT(CS_RELEASE | CS_FUNCTION, 2, printk("cs46xx: cs_release()+ file=%p %s %s\n",
3350 file, file->f_mode & FMODE_WRITE ? "FMODE_WRITE" : "", 3188 file, file->f_mode & FMODE_WRITE ? "FMODE_WRITE" : "",
3351 file->f_mode & FMODE_READ ? "FMODE_READ" : "") ); 3189 file->f_mode & FMODE_READ ? "FMODE_READ" : ""));
3352 3190
3353 if (!(file->f_mode & (FMODE_WRITE | FMODE_READ))) 3191 if (!(file->f_mode & (FMODE_WRITE | FMODE_READ)))
3354 {
3355 return -EINVAL; 3192 return -EINVAL;
3356 }
3357 state = card->states[1]; 3193 state = card->states[1];
3358 if(state) 3194 if (state) {
3359 { 3195 if ((state->open_mode & FMODE_WRITE) & (file->f_mode & FMODE_WRITE)) {
3360 if ( (state->open_mode & FMODE_WRITE) & (file->f_mode & FMODE_WRITE) ) 3196 CS_DBGOUT(CS_RELEASE, 2, printk("cs46xx: cs_release() FMODE_WRITE\n"));
3361 {
3362 CS_DBGOUT(CS_RELEASE, 2, printk("cs46xx: cs_release() FMODE_WRITE\n") );
3363 dmabuf = &state->dmabuf; 3197 dmabuf = &state->dmabuf;
3364 cs_clear_tail(state); 3198 cs_clear_tail(state);
3365 drain_dac(state, file->f_flags & O_NONBLOCK); 3199 drain_dac(state, file->f_flags & O_NONBLOCK);
@@ -3375,8 +3209,7 @@ static int cs_release(struct inode *inode, struct file *file)
3375 state->card->states[state->virt] = NULL; 3209 state->card->states[state->virt] = NULL;
3376 state->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE); 3210 state->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
3377 3211
3378 if( (tmp = cs461x_powerdown(card, CS_POWER_DAC, CS_FALSE )) ) 3212 if ((tmp = cs461x_powerdown(card, CS_POWER_DAC, CS_FALSE))) {
3379 {
3380 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO 3213 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
3381 "cs46xx: cs_release_mixdev() powerdown DAC failure (0x%x)\n",tmp) ); 3214 "cs46xx: cs_release_mixdev() powerdown DAC failure (0x%x)\n",tmp) );
3382 } 3215 }
@@ -3384,17 +3217,14 @@ static int cs_release(struct inode *inode, struct file *file)
3384 /* Now turn off external AMP if needed */ 3217 /* Now turn off external AMP if needed */
3385 state->card->amplifier_ctrl(state->card, -1); 3218 state->card->amplifier_ctrl(state->card, -1);
3386 state->card->active_ctrl(state->card, -1); 3219 state->card->active_ctrl(state->card, -1);
3387
3388 kfree(state); 3220 kfree(state);
3389 } 3221 }
3390 } 3222 }
3391 3223
3392 state = card->states[0]; 3224 state = card->states[0];
3393 if(state) 3225 if (state) {
3394 { 3226 if ((state->open_mode & FMODE_READ) & (file->f_mode & FMODE_READ)) {
3395 if ( (state->open_mode & FMODE_READ) & (file->f_mode & FMODE_READ) ) 3227 CS_DBGOUT(CS_RELEASE, 2, printk("cs46xx: cs_release() FMODE_READ\n"));
3396 {
3397 CS_DBGOUT(CS_RELEASE, 2, printk("cs46xx: cs_release() FMODE_READ\n") );
3398 dmabuf = &state->dmabuf; 3228 dmabuf = &state->dmabuf;
3399 mutex_lock(&state->open_mutex); 3229 mutex_lock(&state->open_mutex);
3400 stop_adc(state); 3230 stop_adc(state);
@@ -3407,8 +3237,7 @@ static int cs_release(struct inode *inode, struct file *file)
3407 state->card->states[state->virt] = NULL; 3237 state->card->states[state->virt] = NULL;
3408 state->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE); 3238 state->open_mode &= (~file->f_mode) & (FMODE_READ|FMODE_WRITE);
3409 3239
3410 if( (tmp = cs461x_powerdown(card, CS_POWER_ADC, CS_FALSE )) ) 3240 if ((tmp = cs461x_powerdown(card, CS_POWER_ADC, CS_FALSE))) {
3411 {
3412 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO 3241 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
3413 "cs46xx: cs_release_mixdev() powerdown ADC failure (0x%x)\n",tmp) ); 3242 "cs46xx: cs_release_mixdev() powerdown ADC failure (0x%x)\n",tmp) );
3414 } 3243 }
@@ -3416,12 +3245,11 @@ static int cs_release(struct inode *inode, struct file *file)
3416 /* Now turn off external AMP if needed */ 3245 /* Now turn off external AMP if needed */
3417 state->card->amplifier_ctrl(state->card, -1); 3246 state->card->amplifier_ctrl(state->card, -1);
3418 state->card->active_ctrl(state->card, -1); 3247 state->card->active_ctrl(state->card, -1);
3419
3420 kfree(state); 3248 kfree(state);
3421 } 3249 }
3422 } 3250 }
3423 3251
3424 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 2, printk("cs46xx: cs_release()- 0\n") ); 3252 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 2, printk("cs46xx: cs_release()- 0\n"));
3425 return 0; 3253 return 0;
3426} 3254}
3427 3255
@@ -3474,21 +3302,18 @@ static void cs46xx_ac97_suspend(struct cs_card *card)
3474 3302
3475 CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_suspend()+\n")); 3303 CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_suspend()+\n"));
3476 3304
3477 if(card->states[1]) 3305 if (card->states[1]) {
3478 {
3479 stop_dac(card->states[1]); 3306 stop_dac(card->states[1]);
3480 resync_dma_ptrs(card->states[1]); 3307 resync_dma_ptrs(card->states[1]);
3481 } 3308 }
3482 if(card->states[0]) 3309 if (card->states[0]) {
3483 {
3484 stop_adc(card->states[0]); 3310 stop_adc(card->states[0]);
3485 resync_dma_ptrs(card->states[0]); 3311 resync_dma_ptrs(card->states[0]);
3486 } 3312 }
3487 3313
3488 for(Count = 0x2, i=0; (Count <= CS46XX_AC97_HIGHESTREGTORESTORE) 3314 for (Count = 0x2, i = 0; (Count <= CS46XX_AC97_HIGHESTREGTORESTORE)
3489 && (i < CS46XX_AC97_NUMBER_RESTORE_REGS); 3315 && (i < CS46XX_AC97_NUMBER_RESTORE_REGS);
3490 Count += 2, i++) 3316 Count += 2, i++) {
3491 {
3492 card->pm.ac97[i] = cs_ac97_get(dev, BA0_AC97_RESET + Count); 3317 card->pm.ac97[i] = cs_ac97_get(dev, BA0_AC97_RESET + Count);
3493 } 3318 }
3494/* 3319/*
@@ -3522,11 +3347,10 @@ static void cs46xx_ac97_suspend(struct cs_card *card)
3522* well, for now, only power down the DAC/ADC and MIXER VREFON components. 3347* well, for now, only power down the DAC/ADC and MIXER VREFON components.
3523* trouble with removing VREF. 3348* trouble with removing VREF.
3524*/ 3349*/
3525 if( (tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC | 3350 if ((tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC |
3526 CS_POWER_MIXVON, CS_TRUE )) ) 3351 CS_POWER_MIXVON, CS_TRUE))) {
3527 {
3528 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO 3352 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
3529 "cs46xx: cs46xx_ac97_suspend() failure (0x%x)\n",tmp) ); 3353 "cs46xx: cs46xx_ac97_suspend() failure (0x%x)\n",tmp));
3530 } 3354 }
3531 3355
3532 CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_suspend()-\n")); 3356 CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_suspend()-\n"));
@@ -3566,16 +3390,13 @@ static void cs46xx_ac97_resume(struct cs_card *card)
3566* Restore just the first set of registers, from register number 3390* Restore just the first set of registers, from register number
3567* 0x02 to the register number that ulHighestRegToRestore specifies. 3391* 0x02 to the register number that ulHighestRegToRestore specifies.
3568*/ 3392*/
3569 for( Count = 0x2, i=0; 3393 for (Count = 0x2, i=0; (Count <= CS46XX_AC97_HIGHESTREGTORESTORE) &&
3570 (Count <= CS46XX_AC97_HIGHESTREGTORESTORE) 3394 (i < CS46XX_AC97_NUMBER_RESTORE_REGS); Count += 2, i++) {
3571 && (i < CS46XX_AC97_NUMBER_RESTORE_REGS);
3572 Count += 2, i++)
3573 {
3574 cs_ac97_set(dev, (u8)(BA0_AC97_RESET + Count), (u16)card->pm.ac97[i]); 3395 cs_ac97_set(dev, (u8)(BA0_AC97_RESET + Count), (u16)card->pm.ac97[i]);
3575 } 3396 }
3576 3397
3577 /* Check if we have to init the amplifier */ 3398 /* Check if we have to init the amplifier */
3578 if(card->amp_init) 3399 if (card->amp_init)
3579 card->amp_init(card); 3400 card->amp_init(card);
3580 3401
3581 CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_resume()-\n")); 3402 CS_DBGOUT(CS_PM, 9, printk("cs46xx: cs46xx_ac97_resume()-\n"));
@@ -3585,30 +3406,27 @@ static void cs46xx_ac97_resume(struct cs_card *card)
3585static int cs46xx_restart_part(struct cs_card *card) 3406static int cs46xx_restart_part(struct cs_card *card)
3586{ 3407{
3587 struct dmabuf *dmabuf; 3408 struct dmabuf *dmabuf;
3409
3588 CS_DBGOUT(CS_PM | CS_FUNCTION, 4, 3410 CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
3589 printk( "cs46xx: cs46xx_restart_part()+\n")); 3411 printk( "cs46xx: cs46xx_restart_part()+\n"));
3590 if(card->states[1]) 3412 if (card->states[1]) {
3591 {
3592 dmabuf = &card->states[1]->dmabuf; 3413 dmabuf = &card->states[1]->dmabuf;
3593 dmabuf->ready = 0; 3414 dmabuf->ready = 0;
3594 resync_dma_ptrs(card->states[1]); 3415 resync_dma_ptrs(card->states[1]);
3595 cs_set_divisor(dmabuf); 3416 cs_set_divisor(dmabuf);
3596 if(__prog_dmabuf(card->states[1])) 3417 if (__prog_dmabuf(card->states[1])) {
3597 {
3598 CS_DBGOUT(CS_PM | CS_ERROR, 1, 3418 CS_DBGOUT(CS_PM | CS_ERROR, 1,
3599 printk("cs46xx: cs46xx_restart_part()- (-1) prog_dmabuf() dac error\n")); 3419 printk("cs46xx: cs46xx_restart_part()- (-1) prog_dmabuf() dac error\n"));
3600 return -1; 3420 return -1;
3601 } 3421 }
3602 cs_set_dac_rate(card->states[1], dmabuf->rate); 3422 cs_set_dac_rate(card->states[1], dmabuf->rate);
3603 } 3423 }
3604 if(card->states[0]) 3424 if (card->states[0]) {
3605 {
3606 dmabuf = &card->states[0]->dmabuf; 3425 dmabuf = &card->states[0]->dmabuf;
3607 dmabuf->ready = 0; 3426 dmabuf->ready = 0;
3608 resync_dma_ptrs(card->states[0]); 3427 resync_dma_ptrs(card->states[0]);
3609 cs_set_divisor(dmabuf); 3428 cs_set_divisor(dmabuf);
3610 if(__prog_dmabuf(card->states[0])) 3429 if (__prog_dmabuf(card->states[0])) {
3611 {
3612 CS_DBGOUT(CS_PM | CS_ERROR, 1, 3430 CS_DBGOUT(CS_PM | CS_ERROR, 1,
3613 printk("cs46xx: cs46xx_restart_part()- (-1) prog_dmabuf() adc error\n")); 3431 printk("cs46xx: cs46xx_restart_part()- (-1) prog_dmabuf() adc error\n"));
3614 return -1; 3432 return -1;
@@ -3616,17 +3434,17 @@ static int cs46xx_restart_part(struct cs_card *card)
3616 cs_set_adc_rate(card->states[0], dmabuf->rate); 3434 cs_set_adc_rate(card->states[0], dmabuf->rate);
3617 } 3435 }
3618 card->pm.flags |= CS46XX_PM_RESUMED; 3436 card->pm.flags |= CS46XX_PM_RESUMED;
3619 if(card->states[0]) 3437 if (card->states[0])
3620 start_adc(card->states[0]); 3438 start_adc(card->states[0]);
3621 if(card->states[1]) 3439 if (card->states[1])
3622 start_dac(card->states[1]); 3440 start_dac(card->states[1]);
3623 3441
3624 card->pm.flags |= CS46XX_PM_IDLE; 3442 card->pm.flags |= CS46XX_PM_IDLE;
3625 card->pm.flags &= ~(CS46XX_PM_SUSPENDING | CS46XX_PM_SUSPENDED 3443 card->pm.flags &= ~(CS46XX_PM_SUSPENDING | CS46XX_PM_SUSPENDED
3626 | CS46XX_PM_RESUMING | CS46XX_PM_RESUMED); 3444 | CS46XX_PM_RESUMING | CS46XX_PM_RESUMED);
3627 if(card->states[0]) 3445 if (card->states[0])
3628 wake_up(&card->states[0]->dmabuf.wait); 3446 wake_up(&card->states[0]->dmabuf.wait);
3629 if(card->states[1]) 3447 if (card->states[1])
3630 wake_up(&card->states[1]->dmabuf.wait); 3448 wake_up(&card->states[1]->dmabuf.wait);
3631 3449
3632 CS_DBGOUT(CS_PM | CS_FUNCTION, 4, 3450 CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
@@ -3634,20 +3452,19 @@ static int cs46xx_restart_part(struct cs_card *card)
3634 return 0; 3452 return 0;
3635} 3453}
3636 3454
3637
3638static void cs461x_reset(struct cs_card *card); 3455static void cs461x_reset(struct cs_card *card);
3639static void cs461x_proc_stop(struct cs_card *card); 3456static void cs461x_proc_stop(struct cs_card *card);
3640static int cs46xx_suspend(struct cs_card *card, pm_message_t state) 3457static int cs46xx_suspend(struct cs_card *card, pm_message_t state)
3641{ 3458{
3642 unsigned int tmp; 3459 unsigned int tmp;
3460
3643 CS_DBGOUT(CS_PM | CS_FUNCTION, 4, 3461 CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
3644 printk("cs46xx: cs46xx_suspend()+ flags=0x%x s=%p\n", 3462 printk("cs46xx: cs46xx_suspend()+ flags=0x%x s=%p\n",
3645 (unsigned)card->pm.flags,card)); 3463 (unsigned)card->pm.flags,card));
3646/* 3464/*
3647* check the current state, only suspend if IDLE 3465* check the current state, only suspend if IDLE
3648*/ 3466*/
3649 if(!(card->pm.flags & CS46XX_PM_IDLE)) 3467 if (!(card->pm.flags & CS46XX_PM_IDLE)) {
3650 {
3651 CS_DBGOUT(CS_PM | CS_ERROR, 2, 3468 CS_DBGOUT(CS_PM | CS_ERROR, 2,
3652 printk("cs46xx: cs46xx_suspend() unable to suspend, not IDLE\n")); 3469 printk("cs46xx: cs46xx_suspend() unable to suspend, not IDLE\n"));
3653 return 1; 3470 return 1;
@@ -3679,13 +3496,11 @@ static int cs46xx_suspend(struct cs_card *card, pm_message_t state)
3679 tmp = cs461x_peek(card, BA1_CCTL); 3496 tmp = cs461x_peek(card, BA1_CCTL);
3680 cs461x_poke(card, BA1_CCTL, tmp & 0xffff0000); 3497 cs461x_poke(card, BA1_CCTL, tmp & 0xffff0000);
3681 3498
3682 if(card->states[1]) 3499 if (card->states[1]) {
3683 {
3684 card->pm.dmabuf_swptr_play = card->states[1]->dmabuf.swptr; 3500 card->pm.dmabuf_swptr_play = card->states[1]->dmabuf.swptr;
3685 card->pm.dmabuf_count_play = card->states[1]->dmabuf.count; 3501 card->pm.dmabuf_count_play = card->states[1]->dmabuf.count;
3686 } 3502 }
3687 if(card->states[0]) 3503 if (card->states[0]) {
3688 {
3689 card->pm.dmabuf_swptr_capture = card->states[0]->dmabuf.swptr; 3504 card->pm.dmabuf_swptr_capture = card->states[0]->dmabuf.swptr;
3690 card->pm.dmabuf_count_capture = card->states[0]->dmabuf.count; 3505 card->pm.dmabuf_count_capture = card->states[0]->dmabuf.count;
3691 } 3506 }
@@ -3736,8 +3551,7 @@ static int cs46xx_resume(struct cs_card *card)
3736 CS_DBGOUT(CS_PM | CS_FUNCTION, 4, 3551 CS_DBGOUT(CS_PM | CS_FUNCTION, 4,
3737 printk( "cs46xx: cs46xx_resume()+ flags=0x%x\n", 3552 printk( "cs46xx: cs46xx_resume()+ flags=0x%x\n",
3738 (unsigned)card->pm.flags)); 3553 (unsigned)card->pm.flags));
3739 if(!(card->pm.flags & CS46XX_PM_SUSPENDED)) 3554 if (!(card->pm.flags & CS46XX_PM_SUSPENDED)) {
3740 {
3741 CS_DBGOUT(CS_PM | CS_ERROR, 2, 3555 CS_DBGOUT(CS_PM | CS_ERROR, 2,
3742 printk("cs46xx: cs46xx_resume() unable to resume, not SUSPENDED\n")); 3556 printk("cs46xx: cs46xx_resume() unable to resume, not SUSPENDED\n"));
3743 return 1; 3557 return 1;
@@ -3747,10 +3561,8 @@ static int cs46xx_resume(struct cs_card *card)
3747 printpm(card); 3561 printpm(card);
3748 card->active_ctrl(card, 1); 3562 card->active_ctrl(card, 1);
3749 3563
3750 for(i=0;i<5;i++) 3564 for (i = 0; i < 5; i++) {
3751 { 3565 if (cs_hardware_init(card) != 0) {
3752 if (cs_hardware_init(card) != 0)
3753 {
3754 CS_DBGOUT(CS_PM | CS_ERROR, 4, printk( 3566 CS_DBGOUT(CS_PM | CS_ERROR, 4, printk(
3755 "cs46xx: cs46xx_resume()- ERROR in cs_hardware_init()\n")); 3567 "cs46xx: cs46xx_resume()- ERROR in cs_hardware_init()\n"));
3756 mdelay(10 * cs_laptop_wait); 3568 mdelay(10 * cs_laptop_wait);
@@ -3759,15 +3571,13 @@ static int cs46xx_resume(struct cs_card *card)
3759 } 3571 }
3760 break; 3572 break;
3761 } 3573 }
3762 if(i>=4) 3574 if (i >= 4) {
3763 {
3764 CS_DBGOUT(CS_PM | CS_ERROR, 1, printk( 3575 CS_DBGOUT(CS_PM | CS_ERROR, 1, printk(
3765 "cs46xx: cs46xx_resume()- cs_hardware_init() failed, retried %d times.\n",i)); 3576 "cs46xx: cs46xx_resume()- cs_hardware_init() failed, retried %d times.\n",i));
3766 return 0; 3577 return 0;
3767 } 3578 }
3768 3579
3769 if(cs46xx_restart_part(card)) 3580 if (cs46xx_restart_part(card)) {
3770 {
3771 CS_DBGOUT(CS_PM | CS_ERROR, 4, printk( 3581 CS_DBGOUT(CS_PM | CS_ERROR, 4, printk(
3772 "cs46xx: cs46xx_resume(): cs46xx_restart_part() returned error\n")); 3582 "cs46xx: cs46xx_resume(): cs46xx_restart_part() returned error\n"));
3773 } 3583 }
@@ -3835,7 +3645,7 @@ static u16 _cs_ac97_get(struct ac97_codec *dev, u8 reg)
3835 /* 3645 /*
3836 * Wait for the read to occur. 3646 * Wait for the read to occur.
3837 */ 3647 */
3838 if(!(card->pm.flags & CS46XX_PM_IDLE)) 3648 if (!(card->pm.flags & CS46XX_PM_IDLE))
3839 loopcnt = 2000; 3649 loopcnt = 2000;
3840 else 3650 else
3841 loopcnt = 500 * cs_laptop_wait; 3651 loopcnt = 500 * cs_laptop_wait;
@@ -3866,7 +3676,7 @@ static u16 _cs_ac97_get(struct ac97_codec *dev, u8 reg)
3866 * Wait for the valid status bit to go active. 3676 * Wait for the valid status bit to go active.
3867 */ 3677 */
3868 3678
3869 if(!(card->pm.flags & CS46XX_PM_IDLE)) 3679 if (!(card->pm.flags & CS46XX_PM_IDLE))
3870 loopcnt = 2000; 3680 loopcnt = 2000;
3871 else 3681 else
3872 loopcnt = 1000; 3682 loopcnt = 1000;
@@ -3885,7 +3695,7 @@ static u16 _cs_ac97_get(struct ac97_codec *dev, u8 reg)
3885 /* 3695 /*
3886 * Make sure we got valid status. 3696 * Make sure we got valid status.
3887 */ 3697 */
3888 if (!( (tmp=cs461x_peekBA0(card, BA0_ACSTS)) & ACSTS_VSTS)) { 3698 if (!((tmp = cs461x_peekBA0(card, BA0_ACSTS)) & ACSTS_VSTS)) {
3889 CS_DBGOUT(CS_ERROR, 2, printk(KERN_WARNING 3699 CS_DBGOUT(CS_ERROR, 2, printk(KERN_WARNING
3890 "cs46xx: AC'97 read problem (ACSTS_VSTS), reg = 0x%x val=0x%x 0xffff \n", 3700 "cs46xx: AC'97 read problem (ACSTS_VSTS), reg = 0x%x val=0x%x 0xffff \n",
3891 reg, tmp)); 3701 reg, tmp));
@@ -3923,12 +3733,9 @@ static void cs_ac97_set(struct ac97_codec *dev, u8 reg, u16 val)
3923 3733
3924 spin_lock(&card->ac97_lock); 3734 spin_lock(&card->ac97_lock);
3925 3735
3926 if(reg == AC97_CD_VOL) 3736 if (reg == AC97_CD_VOL)
3927 {
3928 val2 = _cs_ac97_get(dev, AC97_CD_VOL); 3737 val2 = _cs_ac97_get(dev, AC97_CD_VOL);
3929 } 3738
3930
3931
3932 /* 3739 /*
3933 * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address 3740 * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
3934 * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97 3741 * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97
@@ -3970,8 +3777,7 @@ static void cs_ac97_set(struct ac97_codec *dev, u8 reg, u16 val)
3970 /* 3777 /*
3971 * Make sure the write completed. 3778 * Make sure the write completed.
3972 */ 3779 */
3973 if (cs461x_peekBA0(card, BA0_ACCTL) & ACCTL_DCV) 3780 if (cs461x_peekBA0(card, BA0_ACCTL) & ACCTL_DCV) {
3974 {
3975 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING 3781 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
3976 "cs46xx: AC'97 write problem, reg = 0x%x, val = 0x%x\n", reg, val)); 3782 "cs46xx: AC'97 write problem, reg = 0x%x, val = 0x%x\n", reg, val));
3977 } 3783 }
@@ -3998,25 +3804,23 @@ static void cs_ac97_set(struct ac97_codec *dev, u8 reg, u16 val)
3998 3804
3999 /* CD mute change ? */ 3805 /* CD mute change ? */
4000 3806
4001 if(reg==AC97_CD_VOL) 3807 if (reg == AC97_CD_VOL) {
4002 {
4003 /* Mute bit change ? */ 3808 /* Mute bit change ? */
4004 if((val2^val)&0x8000 || ((val2 == 0x1f1f || val == 0x1f1f) && val2 != val)) 3809 if ((val2^val) & 0x8000 ||
4005 { 3810 ((val2 == 0x1f1f || val == 0x1f1f) && val2 != val)) {
4006 /* This is a hack but its cleaner than the alternatives. 3811 /* This is a hack but its cleaner than the alternatives.
4007 Right now card->ac97_codec[0] might be NULL as we are 3812 Right now card->ac97_codec[0] might be NULL as we are
4008 still doing codec setup. This does an early assignment 3813 still doing codec setup. This does an early assignment
4009 to avoid the problem if it occurs */ 3814 to avoid the problem if it occurs */
4010 3815
4011 if(card->ac97_codec[0]==NULL) 3816 if (card->ac97_codec[0] == NULL)
4012 card->ac97_codec[0]=dev; 3817 card->ac97_codec[0] = dev;
4013 3818
4014 /* Mute on */ 3819 /* Mute on */
4015 if(val&0x8000 || val == 0x1f1f) 3820 if (val & 0x8000 || val == 0x1f1f)
4016 card->amplifier_ctrl(card, -1); 3821 card->amplifier_ctrl(card, -1);
4017 else /* Mute off power on */ 3822 else { /* Mute off power on */
4018 { 3823 if (card->amp_init)
4019 if(card->amp_init)
4020 card->amp_init(card); 3824 card->amp_init(card);
4021 card->amplifier_ctrl(card, 1); 3825 card->amplifier_ctrl(card, 1);
4022 } 3826 }
@@ -4024,46 +3828,41 @@ static void cs_ac97_set(struct ac97_codec *dev, u8 reg, u16 val)
4024 } 3828 }
4025} 3829}
4026 3830
4027
4028/* OSS /dev/mixer file operation methods */ 3831/* OSS /dev/mixer file operation methods */
4029 3832
4030static int cs_open_mixdev(struct inode *inode, struct file *file) 3833static int cs_open_mixdev(struct inode *inode, struct file *file)
4031{ 3834{
4032 int i=0; 3835 int i = 0;
4033 unsigned int minor = iminor(inode); 3836 unsigned int minor = iminor(inode);
4034 struct cs_card *card=NULL; 3837 struct cs_card *card = NULL;
4035 struct list_head *entry; 3838 struct list_head *entry;
4036 unsigned int tmp; 3839 unsigned int tmp;
4037 3840
4038 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4, 3841 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
4039 printk(KERN_INFO "cs46xx: cs_open_mixdev()+\n")); 3842 printk(KERN_INFO "cs46xx: cs_open_mixdev()+\n"));
4040 3843
4041 list_for_each(entry, &cs46xx_devs) 3844 list_for_each(entry, &cs46xx_devs) {
4042 {
4043 card = list_entry(entry, struct cs_card, list); 3845 card = list_entry(entry, struct cs_card, list);
4044 for (i = 0; i < NR_AC97; i++) 3846 for (i = 0; i < NR_AC97; i++)
4045 if (card->ac97_codec[i] != NULL && 3847 if (card->ac97_codec[i] != NULL &&
4046 card->ac97_codec[i]->dev_mixer == minor) 3848 card->ac97_codec[i]->dev_mixer == minor)
4047 goto match; 3849 goto match;
4048 } 3850 }
4049 if (!card) 3851 if (!card) {
4050 {
4051 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2, 3852 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2,
4052 printk(KERN_INFO "cs46xx: cs46xx_open_mixdev()- -ENODEV\n")); 3853 printk(KERN_INFO "cs46xx: cs46xx_open_mixdev()- -ENODEV\n"));
4053 return -ENODEV; 3854 return -ENODEV;
4054 } 3855 }
4055 match: 3856 match:
4056 if(!card->ac97_codec[i]) 3857 if (!card->ac97_codec[i])
4057 return -ENODEV; 3858 return -ENODEV;
4058 file->private_data = card->ac97_codec[i]; 3859 file->private_data = card->ac97_codec[i];
4059 3860
4060 card->active_ctrl(card,1); 3861 card->active_ctrl(card,1);
4061 if(!CS_IN_USE(&card->mixer_use_cnt)) 3862 if (!CS_IN_USE(&card->mixer_use_cnt)) {
4062 { 3863 if ((tmp = cs46xx_powerup(card, CS_POWER_MIXVON))) {
4063 if( (tmp = cs46xx_powerup(card, CS_POWER_MIXVON )) )
4064 {
4065 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO 3864 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
4066 "cs46xx: cs_open_mixdev() powerup failure (0x%x)\n",tmp) ); 3865 "cs46xx: cs_open_mixdev() powerup failure (0x%x)\n", tmp));
4067 return -EIO; 3866 return -EIO;
4068 } 3867 }
4069 } 3868 }
@@ -4077,7 +3876,7 @@ static int cs_open_mixdev(struct inode *inode, struct file *file)
4077static int cs_release_mixdev(struct inode *inode, struct file *file) 3876static int cs_release_mixdev(struct inode *inode, struct file *file)
4078{ 3877{
4079 unsigned int minor = iminor(inode); 3878 unsigned int minor = iminor(inode);
4080 struct cs_card *card=NULL; 3879 struct cs_card *card = NULL;
4081 struct list_head *entry; 3880 struct list_head *entry;
4082 int i; 3881 int i;
4083 unsigned int tmp; 3882 unsigned int tmp;
@@ -4092,15 +3891,13 @@ static int cs_release_mixdev(struct inode *inode, struct file *file)
4092 card->ac97_codec[i]->dev_mixer == minor) 3891 card->ac97_codec[i]->dev_mixer == minor)
4093 goto match; 3892 goto match;
4094 } 3893 }
4095 if (!card) 3894 if (!card) {
4096 {
4097 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2, 3895 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2,
4098 printk(KERN_INFO "cs46xx: cs46xx_open_mixdev()- -ENODEV\n")); 3896 printk(KERN_INFO "cs46xx: cs46xx_open_mixdev()- -ENODEV\n"));
4099 return -ENODEV; 3897 return -ENODEV;
4100 } 3898 }
4101match: 3899match:
4102 if(!CS_DEC_AND_TEST(&card->mixer_use_cnt)) 3900 if (!CS_DEC_AND_TEST(&card->mixer_use_cnt)) {
4103 {
4104 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 4, 3901 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 4,
4105 printk(KERN_INFO "cs46xx: cs_release_mixdev()- no powerdown, usecnt>0\n")); 3902 printk(KERN_INFO "cs46xx: cs_release_mixdev()- no powerdown, usecnt>0\n"));
4106 card->active_ctrl(card, -1); 3903 card->active_ctrl(card, -1);
@@ -4110,10 +3907,9 @@ match:
4110/* 3907/*
4111* ok, no outstanding mixer opens, so powerdown. 3908* ok, no outstanding mixer opens, so powerdown.
4112*/ 3909*/
4113 if( (tmp = cs461x_powerdown(card, CS_POWER_MIXVON, CS_FALSE )) ) 3910 if ((tmp = cs461x_powerdown(card, CS_POWER_MIXVON, CS_FALSE))) {
4114 {
4115 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO 3911 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
4116 "cs46xx: cs_release_mixdev() powerdown MIXVON failure (0x%x)\n",tmp) ); 3912 "cs46xx: cs_release_mixdev() powerdown MIXVON failure (0x%x)\n", tmp));
4117 card->active_ctrl(card, -1); 3913 card->active_ctrl(card, -1);
4118 card->amplifier_ctrl(card, -1); 3914 card->amplifier_ctrl(card, -1);
4119 return -EIO; 3915 return -EIO;
@@ -4126,76 +3922,60 @@ match:
4126} 3922}
4127 3923
4128static int cs_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd, 3924static int cs_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
4129 unsigned long arg) 3925 unsigned long arg)
4130{ 3926{
4131 struct ac97_codec *codec = (struct ac97_codec *)file->private_data; 3927 struct ac97_codec *codec = file->private_data;
4132 struct cs_card *card=NULL; 3928 struct cs_card *card = NULL;
4133 struct list_head *entry; 3929 struct list_head *entry;
4134 unsigned long __user *p = (long __user *)arg; 3930 unsigned long __user *p = (long __user *)arg;
4135
4136#if CSDEBUG_INTERFACE 3931#if CSDEBUG_INTERFACE
4137 int val; 3932 int val;
4138 3933
4139 if( (cmd == SOUND_MIXER_CS_GETDBGMASK) || 3934 if ( (cmd == SOUND_MIXER_CS_GETDBGMASK) ||
4140 (cmd == SOUND_MIXER_CS_SETDBGMASK) || 3935 (cmd == SOUND_MIXER_CS_SETDBGMASK) ||
4141 (cmd == SOUND_MIXER_CS_GETDBGLEVEL) || 3936 (cmd == SOUND_MIXER_CS_GETDBGLEVEL) ||
4142 (cmd == SOUND_MIXER_CS_SETDBGLEVEL) || 3937 (cmd == SOUND_MIXER_CS_SETDBGLEVEL) ||
4143 (cmd == SOUND_MIXER_CS_APM)) 3938 (cmd == SOUND_MIXER_CS_APM)) {
4144 { 3939 switch (cmd) {
4145 switch(cmd)
4146 {
4147
4148 case SOUND_MIXER_CS_GETDBGMASK: 3940 case SOUND_MIXER_CS_GETDBGMASK:
4149 return put_user(cs_debugmask, p); 3941 return put_user(cs_debugmask, p);
4150
4151 case SOUND_MIXER_CS_GETDBGLEVEL: 3942 case SOUND_MIXER_CS_GETDBGLEVEL:
4152 return put_user(cs_debuglevel, p); 3943 return put_user(cs_debuglevel, p);
4153
4154 case SOUND_MIXER_CS_SETDBGMASK: 3944 case SOUND_MIXER_CS_SETDBGMASK:
4155 if (get_user(val, p)) 3945 if (get_user(val, p))
4156 return -EFAULT; 3946 return -EFAULT;
4157 cs_debugmask = val; 3947 cs_debugmask = val;
4158 return 0; 3948 return 0;
4159
4160 case SOUND_MIXER_CS_SETDBGLEVEL: 3949 case SOUND_MIXER_CS_SETDBGLEVEL:
4161 if (get_user(val, p)) 3950 if (get_user(val, p))
4162 return -EFAULT; 3951 return -EFAULT;
4163 cs_debuglevel = val; 3952 cs_debuglevel = val;
4164 return 0; 3953 return 0;
4165
4166 case SOUND_MIXER_CS_APM: 3954 case SOUND_MIXER_CS_APM:
4167 if (get_user(val, p)) 3955 if (get_user(val, p))
4168 return -EFAULT; 3956 return -EFAULT;
4169 if(val == CS_IOCTL_CMD_SUSPEND) 3957 if (val == CS_IOCTL_CMD_SUSPEND) {
4170 { 3958 list_for_each(entry, &cs46xx_devs) {
4171 list_for_each(entry, &cs46xx_devs)
4172 {
4173 card = list_entry(entry, struct cs_card, list); 3959 card = list_entry(entry, struct cs_card, list);
4174 cs46xx_suspend(card, PMSG_ON); 3960 cs46xx_suspend(card, PMSG_ON);
4175 } 3961 }
4176 3962
4177 } 3963 } else if (val == CS_IOCTL_CMD_RESUME) {
4178 else if(val == CS_IOCTL_CMD_RESUME) 3964 list_for_each(entry, &cs46xx_devs) {
4179 {
4180 list_for_each(entry, &cs46xx_devs)
4181 {
4182 card = list_entry(entry, struct cs_card, list); 3965 card = list_entry(entry, struct cs_card, list);
4183 cs46xx_resume(card); 3966 cs46xx_resume(card);
4184 } 3967 }
4185 } 3968 } else {
4186 else
4187 {
4188 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO 3969 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
4189 "cs46xx: mixer_ioctl(): invalid APM cmd (%d)\n", 3970 "cs46xx: mixer_ioctl(): invalid APM cmd (%d)\n",
4190 val)); 3971 val));
4191 } 3972 }
4192 return 0; 3973 return 0;
4193
4194 default: 3974 default:
4195 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO 3975 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
4196 "cs46xx: mixer_ioctl(): ERROR unknown debug cmd\n") ); 3976 "cs46xx: mixer_ioctl(): ERROR unknown debug cmd\n"));
4197 return 0; 3977 return 0;
4198 } 3978 }
4199 } 3979 }
4200#endif 3980#endif
4201 return codec->mixer_ioctl(codec, cmd, arg); 3981 return codec->mixer_ioctl(codec, cmd, arg);
@@ -4232,8 +4012,7 @@ static int __init cs_ac97_init(struct cs_card *card)
4232 codec->codec_read = cs_ac97_get; 4012 codec->codec_read = cs_ac97_get;
4233 codec->codec_write = cs_ac97_set; 4013 codec->codec_write = cs_ac97_set;
4234 4014
4235 if (ac97_probe_codec(codec) == 0) 4015 if (ac97_probe_codec(codec) == 0) {
4236 {
4237 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO 4016 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
4238 "cs46xx: cs_ac97_init()- codec number %d not found\n", 4017 "cs46xx: cs_ac97_init()- codec number %d not found\n",
4239 num_ac97) ); 4018 num_ac97) );
@@ -4241,12 +4020,11 @@ static int __init cs_ac97_init(struct cs_card *card)
4241 break; 4020 break;
4242 } 4021 }
4243 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO 4022 CS_DBGOUT(CS_FUNCTION | CS_INIT, 2, printk(KERN_INFO
4244 "cs46xx: cs_ac97_init() found codec %d\n",num_ac97) ); 4023 "cs46xx: cs_ac97_init() found codec %d\n",num_ac97));
4245 4024
4246 eid = cs_ac97_get(codec, AC97_EXTENDED_ID); 4025 eid = cs_ac97_get(codec, AC97_EXTENDED_ID);
4247 4026
4248 if(eid==0xFFFF) 4027 if (eid == 0xFFFF) {
4249 {
4250 printk(KERN_WARNING "cs46xx: codec %d not present\n",num_ac97); 4028 printk(KERN_WARNING "cs46xx: codec %d not present\n",num_ac97);
4251 ac97_release_codec(codec); 4029 ac97_release_codec(codec);
4252 break; 4030 break;
@@ -4285,27 +4063,23 @@ static void cs461x_download_image(struct cs_card *card)
4285{ 4063{
4286 unsigned i, j, temp1, temp2, offset, count; 4064 unsigned i, j, temp1, temp2, offset, count;
4287 unsigned char __iomem *pBA1 = ioremap(card->ba1_addr, 0x40000); 4065 unsigned char __iomem *pBA1 = ioremap(card->ba1_addr, 0x40000);
4288 for( i=0; i < CLEAR__COUNT; i++) 4066 for (i = 0; i < CLEAR__COUNT; i++) {
4289 {
4290 offset = ClrStat[i].BA1__DestByteOffset; 4067 offset = ClrStat[i].BA1__DestByteOffset;
4291 count = ClrStat[i].BA1__SourceSize; 4068 count = ClrStat[i].BA1__SourceSize;
4292 for( temp1 = offset; temp1<(offset+count); temp1+=4 ) 4069 for (temp1 = offset; temp1 < (offset + count); temp1 += 4)
4293 writel(0, pBA1+temp1); 4070 writel(0, pBA1+temp1);
4294 } 4071 }
4295 4072
4296 for(i=0; i<FILL__COUNT; i++) 4073 for (i = 0; i < FILL__COUNT; i++) {
4297 {
4298 temp2 = FillStat[i].Offset; 4074 temp2 = FillStat[i].Offset;
4299 for(j=0; j<(FillStat[i].Size)/4; j++) 4075 for (j = 0; j < (FillStat[i].Size) / 4; j++) {
4300 {
4301 temp1 = (FillStat[i]).pFill[j]; 4076 temp1 = (FillStat[i]).pFill[j];
4302 writel(temp1, pBA1+temp2+j*4); 4077 writel(temp1, pBA1+temp2 + j * 4);
4303 } 4078 }
4304 } 4079 }
4305 iounmap(pBA1); 4080 iounmap(pBA1);
4306} 4081}
4307 4082
4308
4309/* 4083/*
4310 * Chip reset 4084 * Chip reset
4311 */ 4085 */
@@ -4365,15 +4139,13 @@ static void cs461x_clear_serial_FIFOs(struct cs_card *card, int type)
4365 * playing or capturing then we don't want to put in 128 bytes of 4139 * playing or capturing then we don't want to put in 128 bytes of
4366 * "noise". 4140 * "noise".
4367 */ 4141 */
4368 if(type & CS_TYPE_DAC) 4142 if (type & CS_TYPE_DAC) {
4369 {
4370 startfifo = 128; 4143 startfifo = 128;
4371 endfifo = 256; 4144 endfifo = 256;
4372 } 4145 }
4373 if(type & CS_TYPE_ADC) 4146 if (type & CS_TYPE_ADC) {
4374 {
4375 startfifo = 0; 4147 startfifo = 0;
4376 if(!endfifo) 4148 if (!endfifo)
4377 endfifo = 128; 4149 endfifo = 128;
4378 } 4150 }
4379 /* 4151 /*
@@ -4417,8 +4189,7 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4417 4189
4418 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO 4190 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
4419 "cs46xx: cs461x_powerdown()+ type=0x%x\n",type)); 4191 "cs46xx: cs461x_powerdown()+ type=0x%x\n",type));
4420 if(!cs_powerdown && !suspendflag) 4192 if (!cs_powerdown && !suspendflag) {
4421 {
4422 CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO 4193 CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
4423 "cs46xx: cs461x_powerdown() DISABLED exiting\n")); 4194 "cs46xx: cs461x_powerdown() DISABLED exiting\n"));
4424 return 0; 4195 return 0;
@@ -4432,12 +4203,11 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4432* currently powered down. If powering down DAC and ADC, then 4203* currently powered down. If powering down DAC and ADC, then
4433* it is possible to power down the VREF (ON). 4204* it is possible to power down the VREF (ON).
4434*/ 4205*/
4435 if ( ((type & CS_POWER_MIXVON) && 4206 if (((type & CS_POWER_MIXVON) &&
4436 (!(type & CS_POWER_ADC) || (!(type & CS_POWER_DAC))) ) 4207 (!(type & CS_POWER_ADC) || (!(type & CS_POWER_DAC))))
4437 && 4208 &&
4438 ((tmp & CS_AC97_POWER_CONTROL_ADC_ON) || 4209 ((tmp & CS_AC97_POWER_CONTROL_ADC_ON) ||
4439 (tmp & CS_AC97_POWER_CONTROL_DAC_ON) ) ) 4210 (tmp & CS_AC97_POWER_CONTROL_DAC_ON))) {
4440 {
4441 CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO 4211 CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
4442 "cs46xx: cs461x_powerdown()- 0 unable to powerdown. tmp=0x%x\n",tmp)); 4212 "cs46xx: cs461x_powerdown()- 0 unable to powerdown. tmp=0x%x\n",tmp));
4443 return 0; 4213 return 0;
@@ -4452,8 +4222,7 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4452 /* 4222 /*
4453 * Power down indicated areas. 4223 * Power down indicated areas.
4454 */ 4224 */
4455 if(type & CS_POWER_MIXVOFF) 4225 if (type & CS_POWER_MIXVOFF) {
4456 {
4457 4226
4458 CS_DBGOUT(CS_FUNCTION, 4, 4227 CS_DBGOUT(CS_FUNCTION, 4,
4459 printk(KERN_INFO "cs46xx: cs461x_powerdown()+ MIXVOFF\n")); 4228 printk(KERN_INFO "cs46xx: cs461x_powerdown()+ MIXVOFF\n"));
@@ -4461,12 +4230,10 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4461 * Power down the MIXER (VREF ON) on the AC97 card. 4230 * Power down the MIXER (VREF ON) on the AC97 card.
4462 */ 4231 */
4463 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL); 4232 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4464 if (tmp & CS_AC97_POWER_CONTROL_MIXVOFF_ON) 4233 if (tmp & CS_AC97_POWER_CONTROL_MIXVOFF_ON) {
4465 { 4234 if (!muted) {
4466 if(!muted)
4467 {
4468 cs_mute(card, CS_TRUE); 4235 cs_mute(card, CS_TRUE);
4469 muted=1; 4236 muted = 1;
4470 } 4237 }
4471 tmp |= CS_AC97_POWER_CONTROL_MIXVOFF; 4238 tmp |= CS_AC97_POWER_CONTROL_MIXVOFF;
4472 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp ); 4239 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
@@ -4492,16 +4259,14 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4492 * Check the status.. 4259 * Check the status..
4493 */ 4260 */
4494 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) & 4261 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4495 CS_AC97_POWER_CONTROL_MIXVOFF_ON) 4262 CS_AC97_POWER_CONTROL_MIXVOFF_ON) {
4496 {
4497 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING 4263 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4498 "cs46xx: powerdown MIXVOFF failed\n")); 4264 "cs46xx: powerdown MIXVOFF failed\n"));
4499 return 1; 4265 return 1;
4500 } 4266 }
4501 } 4267 }
4502 } 4268 }
4503 if(type & CS_POWER_MIXVON) 4269 if (type & CS_POWER_MIXVON) {
4504 {
4505 4270
4506 CS_DBGOUT(CS_FUNCTION, 4, 4271 CS_DBGOUT(CS_FUNCTION, 4,
4507 printk(KERN_INFO "cs46xx: cs461x_powerdown()+ MIXVON\n")); 4272 printk(KERN_INFO "cs46xx: cs461x_powerdown()+ MIXVON\n"));
@@ -4509,15 +4274,13 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4509 * Power down the MIXER (VREF ON) on the AC97 card. 4274 * Power down the MIXER (VREF ON) on the AC97 card.
4510 */ 4275 */
4511 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL); 4276 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4512 if (tmp & CS_AC97_POWER_CONTROL_MIXVON_ON) 4277 if (tmp & CS_AC97_POWER_CONTROL_MIXVON_ON) {
4513 { 4278 if (!muted) {
4514 if(!muted)
4515 {
4516 cs_mute(card, CS_TRUE); 4279 cs_mute(card, CS_TRUE);
4517 muted=1; 4280 muted = 1;
4518 } 4281 }
4519 tmp |= CS_AC97_POWER_CONTROL_MIXVON; 4282 tmp |= CS_AC97_POWER_CONTROL_MIXVON;
4520 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp ); 4283 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp);
4521 /* 4284 /*
4522 * Now, we wait until we sample a ready state. 4285 * Now, we wait until we sample a ready state.
4523 */ 4286 */
@@ -4540,30 +4303,26 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4540 * Check the status.. 4303 * Check the status..
4541 */ 4304 */
4542 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) & 4305 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4543 CS_AC97_POWER_CONTROL_MIXVON_ON) 4306 CS_AC97_POWER_CONTROL_MIXVON_ON) {
4544 {
4545 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING 4307 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4546 "cs46xx: powerdown MIXVON failed\n")); 4308 "cs46xx: powerdown MIXVON failed\n"));
4547 return 1; 4309 return 1;
4548 } 4310 }
4549 } 4311 }
4550 } 4312 }
4551 if(type & CS_POWER_ADC) 4313 if (type & CS_POWER_ADC) {
4552 {
4553 /* 4314 /*
4554 * Power down the ADC on the AC97 card. 4315 * Power down the ADC on the AC97 card.
4555 */ 4316 */
4556 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO "cs46xx: cs461x_powerdown()+ ADC\n")); 4317 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO "cs46xx: cs461x_powerdown()+ ADC\n"));
4557 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL); 4318 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4558 if (tmp & CS_AC97_POWER_CONTROL_ADC_ON) 4319 if (tmp & CS_AC97_POWER_CONTROL_ADC_ON) {
4559 { 4320 if (!muted) {
4560 if(!muted)
4561 {
4562 cs_mute(card, CS_TRUE); 4321 cs_mute(card, CS_TRUE);
4563 muted=1; 4322 muted = 1;
4564 } 4323 }
4565 tmp |= CS_AC97_POWER_CONTROL_ADC; 4324 tmp |= CS_AC97_POWER_CONTROL_ADC;
4566 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp ); 4325 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp);
4567 4326
4568 /* 4327 /*
4569 * Now, we wait until we sample a ready state. 4328 * Now, we wait until we sample a ready state.
@@ -4587,16 +4346,14 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4587 * Check the status.. 4346 * Check the status..
4588 */ 4347 */
4589 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) & 4348 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4590 CS_AC97_POWER_CONTROL_ADC_ON) 4349 CS_AC97_POWER_CONTROL_ADC_ON) {
4591 {
4592 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING 4350 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4593 "cs46xx: powerdown ADC failed\n")); 4351 "cs46xx: powerdown ADC failed\n"));
4594 return 1; 4352 return 1;
4595 } 4353 }
4596 } 4354 }
4597 } 4355 }
4598 if(type & CS_POWER_DAC) 4356 if (type & CS_POWER_DAC) {
4599 {
4600 /* 4357 /*
4601 * Power down the DAC on the AC97 card. 4358 * Power down the DAC on the AC97 card.
4602 */ 4359 */
@@ -4604,15 +4361,13 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4604 CS_DBGOUT(CS_FUNCTION, 4, 4361 CS_DBGOUT(CS_FUNCTION, 4,
4605 printk(KERN_INFO "cs46xx: cs461x_powerdown()+ DAC\n")); 4362 printk(KERN_INFO "cs46xx: cs461x_powerdown()+ DAC\n"));
4606 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL); 4363 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4607 if (tmp & CS_AC97_POWER_CONTROL_DAC_ON) 4364 if (tmp & CS_AC97_POWER_CONTROL_DAC_ON) {
4608 { 4365 if (!muted) {
4609 if(!muted)
4610 {
4611 cs_mute(card, CS_TRUE); 4366 cs_mute(card, CS_TRUE);
4612 muted=1; 4367 muted = 1;
4613 } 4368 }
4614 tmp |= CS_AC97_POWER_CONTROL_DAC; 4369 tmp |= CS_AC97_POWER_CONTROL_DAC;
4615 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp ); 4370 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp);
4616 /* 4371 /*
4617 * Now, we wait until we sample a ready state. 4372 * Now, we wait until we sample a ready state.
4618 */ 4373 */
@@ -4635,8 +4390,7 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4635 * Check the status.. 4390 * Check the status..
4636 */ 4391 */
4637 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) & 4392 if (cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4638 CS_AC97_POWER_CONTROL_DAC_ON) 4393 CS_AC97_POWER_CONTROL_DAC_ON) {
4639 {
4640 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING 4394 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4641 "cs46xx: powerdown DAC failed\n")); 4395 "cs46xx: powerdown DAC failed\n"));
4642 return 1; 4396 return 1;
@@ -4644,7 +4398,7 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4644 } 4398 }
4645 } 4399 }
4646 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL); 4400 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4647 if(muted) 4401 if (muted)
4648 cs_mute(card, CS_FALSE); 4402 cs_mute(card, CS_FALSE);
4649 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO 4403 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
4650 "cs46xx: cs461x_powerdown()- 0 tmp=0x%x\n",tmp)); 4404 "cs46xx: cs461x_powerdown()- 0 tmp=0x%x\n",tmp));
@@ -4654,23 +4408,22 @@ static int cs461x_powerdown(struct cs_card *card, unsigned int type, int suspend
4654static int cs46xx_powerup(struct cs_card *card, unsigned int type) 4408static int cs46xx_powerup(struct cs_card *card, unsigned int type)
4655{ 4409{
4656 int count; 4410 int count;
4657 unsigned int tmp=0,muted=0; 4411 unsigned int tmp = 0, muted = 0;
4658 4412
4659 CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO 4413 CS_DBGOUT(CS_FUNCTION, 8, printk(KERN_INFO
4660 "cs46xx: cs46xx_powerup()+ type=0x%x\n",type)); 4414 "cs46xx: cs46xx_powerup()+ type=0x%x\n",type));
4661 /* 4415 /*
4662 * check for VREF and powerup if need to. 4416 * check for VREF and powerup if need to.
4663 */ 4417 */
4664 if(type & CS_POWER_MIXVON) 4418 if (type & CS_POWER_MIXVON)
4665 type |= CS_POWER_MIXVOFF; 4419 type |= CS_POWER_MIXVOFF;
4666 if(type & (CS_POWER_DAC | CS_POWER_ADC)) 4420 if (type & (CS_POWER_DAC | CS_POWER_ADC))
4667 type |= CS_POWER_MIXVON | CS_POWER_MIXVOFF; 4421 type |= CS_POWER_MIXVON | CS_POWER_MIXVOFF;
4668 4422
4669 /* 4423 /*
4670 * Power up indicated areas. 4424 * Power up indicated areas.
4671 */ 4425 */
4672 if(type & CS_POWER_MIXVOFF) 4426 if (type & CS_POWER_MIXVOFF) {
4673 {
4674 4427
4675 CS_DBGOUT(CS_FUNCTION, 4, 4428 CS_DBGOUT(CS_FUNCTION, 4,
4676 printk(KERN_INFO "cs46xx: cs46xx_powerup()+ MIXVOFF\n")); 4429 printk(KERN_INFO "cs46xx: cs46xx_powerup()+ MIXVOFF\n"));
@@ -4678,12 +4431,10 @@ static int cs46xx_powerup(struct cs_card *card, unsigned int type)
4678 * Power up the MIXER (VREF ON) on the AC97 card. 4431 * Power up the MIXER (VREF ON) on the AC97 card.
4679 */ 4432 */
4680 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL); 4433 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4681 if (!(tmp & CS_AC97_POWER_CONTROL_MIXVOFF_ON)) 4434 if (!(tmp & CS_AC97_POWER_CONTROL_MIXVOFF_ON)) {
4682 { 4435 if (!muted) {
4683 if(!muted)
4684 {
4685 cs_mute(card, CS_TRUE); 4436 cs_mute(card, CS_TRUE);
4686 muted=1; 4437 muted = 1;
4687 } 4438 }
4688 tmp &= ~CS_AC97_POWER_CONTROL_MIXVOFF; 4439 tmp &= ~CS_AC97_POWER_CONTROL_MIXVOFF;
4689 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp ); 4440 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
@@ -4709,16 +4460,14 @@ static int cs46xx_powerup(struct cs_card *card, unsigned int type)
4709 * Check the status.. 4460 * Check the status..
4710 */ 4461 */
4711 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) & 4462 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4712 CS_AC97_POWER_CONTROL_MIXVOFF_ON)) 4463 CS_AC97_POWER_CONTROL_MIXVOFF_ON)) {
4713 {
4714 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING 4464 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4715 "cs46xx: powerup MIXVOFF failed\n")); 4465 "cs46xx: powerup MIXVOFF failed\n"));
4716 return 1; 4466 return 1;
4717 } 4467 }
4718 } 4468 }
4719 } 4469 }
4720 if(type & CS_POWER_MIXVON) 4470 if(type & CS_POWER_MIXVON) {
4721 {
4722 4471
4723 CS_DBGOUT(CS_FUNCTION, 4, 4472 CS_DBGOUT(CS_FUNCTION, 4,
4724 printk(KERN_INFO "cs46xx: cs46xx_powerup()+ MIXVON\n")); 4473 printk(KERN_INFO "cs46xx: cs46xx_powerup()+ MIXVON\n"));
@@ -4726,12 +4475,10 @@ static int cs46xx_powerup(struct cs_card *card, unsigned int type)
4726 * Power up the MIXER (VREF ON) on the AC97 card. 4475 * Power up the MIXER (VREF ON) on the AC97 card.
4727 */ 4476 */
4728 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL); 4477 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4729 if (!(tmp & CS_AC97_POWER_CONTROL_MIXVON_ON)) 4478 if (!(tmp & CS_AC97_POWER_CONTROL_MIXVON_ON)) {
4730 { 4479 if (!muted) {
4731 if(!muted)
4732 {
4733 cs_mute(card, CS_TRUE); 4480 cs_mute(card, CS_TRUE);
4734 muted=1; 4481 muted = 1;
4735 } 4482 }
4736 tmp &= ~CS_AC97_POWER_CONTROL_MIXVON; 4483 tmp &= ~CS_AC97_POWER_CONTROL_MIXVON;
4737 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp ); 4484 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
@@ -4757,27 +4504,23 @@ static int cs46xx_powerup(struct cs_card *card, unsigned int type)
4757 * Check the status.. 4504 * Check the status..
4758 */ 4505 */
4759 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) & 4506 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4760 CS_AC97_POWER_CONTROL_MIXVON_ON)) 4507 CS_AC97_POWER_CONTROL_MIXVON_ON)) {
4761 {
4762 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING 4508 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4763 "cs46xx: powerup MIXVON failed\n")); 4509 "cs46xx: powerup MIXVON failed\n"));
4764 return 1; 4510 return 1;
4765 } 4511 }
4766 } 4512 }
4767 } 4513 }
4768 if(type & CS_POWER_ADC) 4514 if (type & CS_POWER_ADC) {
4769 {
4770 /* 4515 /*
4771 * Power up the ADC on the AC97 card. 4516 * Power up the ADC on the AC97 card.
4772 */ 4517 */
4773 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO "cs46xx: cs46xx_powerup()+ ADC\n")); 4518 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO "cs46xx: cs46xx_powerup()+ ADC\n"));
4774 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL); 4519 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4775 if (!(tmp & CS_AC97_POWER_CONTROL_ADC_ON)) 4520 if (!(tmp & CS_AC97_POWER_CONTROL_ADC_ON)) {
4776 { 4521 if (!muted) {
4777 if(!muted)
4778 {
4779 cs_mute(card, CS_TRUE); 4522 cs_mute(card, CS_TRUE);
4780 muted=1; 4523 muted = 1;
4781 } 4524 }
4782 tmp &= ~CS_AC97_POWER_CONTROL_ADC; 4525 tmp &= ~CS_AC97_POWER_CONTROL_ADC;
4783 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp ); 4526 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
@@ -4804,16 +4547,14 @@ static int cs46xx_powerup(struct cs_card *card, unsigned int type)
4804 * Check the status.. 4547 * Check the status..
4805 */ 4548 */
4806 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) & 4549 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4807 CS_AC97_POWER_CONTROL_ADC_ON)) 4550 CS_AC97_POWER_CONTROL_ADC_ON)) {
4808 {
4809 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING 4551 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4810 "cs46xx: powerup ADC failed\n")); 4552 "cs46xx: powerup ADC failed\n"));
4811 return 1; 4553 return 1;
4812 } 4554 }
4813 } 4555 }
4814 } 4556 }
4815 if(type & CS_POWER_DAC) 4557 if (type & CS_POWER_DAC) {
4816 {
4817 /* 4558 /*
4818 * Power up the DAC on the AC97 card. 4559 * Power up the DAC on the AC97 card.
4819 */ 4560 */
@@ -4821,12 +4562,10 @@ static int cs46xx_powerup(struct cs_card *card, unsigned int type)
4821 CS_DBGOUT(CS_FUNCTION, 4, 4562 CS_DBGOUT(CS_FUNCTION, 4,
4822 printk(KERN_INFO "cs46xx: cs46xx_powerup()+ DAC\n")); 4563 printk(KERN_INFO "cs46xx: cs46xx_powerup()+ DAC\n"));
4823 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL); 4564 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4824 if (!(tmp & CS_AC97_POWER_CONTROL_DAC_ON)) 4565 if (!(tmp & CS_AC97_POWER_CONTROL_DAC_ON)) {
4825 { 4566 if (!muted) {
4826 if(!muted)
4827 {
4828 cs_mute(card, CS_TRUE); 4567 cs_mute(card, CS_TRUE);
4829 muted=1; 4568 muted = 1;
4830 } 4569 }
4831 tmp &= ~CS_AC97_POWER_CONTROL_DAC; 4570 tmp &= ~CS_AC97_POWER_CONTROL_DAC;
4832 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp ); 4571 cs_ac97_set(card->ac97_codec[0], AC97_POWER_CONTROL, tmp );
@@ -4852,8 +4591,7 @@ static int cs46xx_powerup(struct cs_card *card, unsigned int type)
4852 * Check the status.. 4591 * Check the status..
4853 */ 4592 */
4854 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) & 4593 if (!(cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL) &
4855 CS_AC97_POWER_CONTROL_DAC_ON)) 4594 CS_AC97_POWER_CONTROL_DAC_ON)) {
4856 {
4857 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING 4595 CS_DBGOUT(CS_ERROR, 1, printk(KERN_WARNING
4858 "cs46xx: powerup DAC failed\n")); 4596 "cs46xx: powerup DAC failed\n"));
4859 return 1; 4597 return 1;
@@ -4861,14 +4599,13 @@ static int cs46xx_powerup(struct cs_card *card, unsigned int type)
4861 } 4599 }
4862 } 4600 }
4863 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL); 4601 tmp = cs_ac97_get(card->ac97_codec[0], AC97_POWER_CONTROL);
4864 if(muted) 4602 if (muted)
4865 cs_mute(card, CS_FALSE); 4603 cs_mute(card, CS_FALSE);
4866 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO 4604 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
4867 "cs46xx: cs46xx_powerup()- 0 tmp=0x%x\n",tmp)); 4605 "cs46xx: cs46xx_powerup()- 0 tmp=0x%x\n",tmp));
4868 return 0; 4606 return 0;
4869} 4607}
4870 4608
4871
4872static void cs461x_proc_start(struct cs_card *card) 4609static void cs461x_proc_start(struct cs_card *card)
4873{ 4610{
4874 int cnt; 4611 int cnt;
@@ -4965,7 +4702,7 @@ static int cs_hardware_init(struct cs_card *card)
4965 * is not enough for some platforms! tested on an IBM Thinkpads and 4702 * is not enough for some platforms! tested on an IBM Thinkpads and
4966 * reference cards. 4703 * reference cards.
4967 */ 4704 */
4968 if(!(card->pm.flags & CS46XX_PM_IDLE)) 4705 if (!(card->pm.flags & CS46XX_PM_IDLE))
4969 mdelay(initdelay); 4706 mdelay(initdelay);
4970 /* 4707 /*
4971 * Write the selected clock control setup to the hardware. Do not turn on 4708 * Write the selected clock control setup to the hardware. Do not turn on
@@ -5017,8 +4754,7 @@ static int cs_hardware_init(struct cs_card *card)
5017* If we are resuming under 2.2.x then we can not schedule a timeout. 4754* If we are resuming under 2.2.x then we can not schedule a timeout.
5018* so, just spin the CPU. 4755* so, just spin the CPU.
5019*/ 4756*/
5020 if(card->pm.flags & CS46XX_PM_IDLE) 4757 if (card->pm.flags & CS46XX_PM_IDLE) {
5021 {
5022 /* 4758 /*
5023 * Wait for the card ready signal from the AC97 card. 4759 * Wait for the card ready signal from the AC97 card.
5024 */ 4760 */
@@ -5033,9 +4769,7 @@ static int cs_hardware_init(struct cs_card *card)
5033 current->state = TASK_UNINTERRUPTIBLE; 4769 current->state = TASK_UNINTERRUPTIBLE;
5034 schedule_timeout(1); 4770 schedule_timeout(1);
5035 } while (time_before(jiffies, end_time)); 4771 } while (time_before(jiffies, end_time));
5036 } 4772 } else {
5037 else
5038 {
5039 for (count = 0; count < 100; count++) { 4773 for (count = 0; count < 100; count++) {
5040 // First, we want to wait for a short time. 4774 // First, we want to wait for a short time.
5041 udelay(25 * cs_laptop_wait); 4775 udelay(25 * cs_laptop_wait);
@@ -5064,8 +4798,7 @@ static int cs_hardware_init(struct cs_card *card)
5064 */ 4798 */
5065 cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); 4799 cs461x_pokeBA0(card, BA0_ACCTL, ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN);
5066 4800
5067 if(card->pm.flags & CS46XX_PM_IDLE) 4801 if (card->pm.flags & CS46XX_PM_IDLE) {
5068 {
5069 /* 4802 /*
5070 * Wait until we've sampled input slots 3 and 4 as valid, meaning that 4803 * Wait until we've sampled input slots 3 and 4 as valid, meaning that
5071 * the card is pumping ADC data across the AC-link. 4804 * the card is pumping ADC data across the AC-link.
@@ -5081,9 +4814,7 @@ static int cs_hardware_init(struct cs_card *card)
5081 current->state = TASK_UNINTERRUPTIBLE; 4814 current->state = TASK_UNINTERRUPTIBLE;
5082 schedule_timeout(1); 4815 schedule_timeout(1);
5083 } while (time_before(jiffies, end_time)); 4816 } while (time_before(jiffies, end_time));
5084 } 4817 } else {
5085 else
5086 {
5087 for (count = 0; count < 100; count++) { 4818 for (count = 0; count < 100; count++) {
5088 // First, we want to wait for a short time. 4819 // First, we want to wait for a short time.
5089 udelay(25 * cs_laptop_wait); 4820 udelay(25 * cs_laptop_wait);
@@ -5140,17 +4871,13 @@ static int cs_hardware_init(struct cs_card *card)
5140 cs461x_poke(card, BA1_CCTL, tmp & 0xffff0000); 4871 cs461x_poke(card, BA1_CCTL, tmp & 0xffff0000);
5141 4872
5142 /* initialize AC97 codec and register /dev/mixer */ 4873 /* initialize AC97 codec and register /dev/mixer */
5143 if(card->pm.flags & CS46XX_PM_IDLE) 4874 if (card->pm.flags & CS46XX_PM_IDLE) {
5144 { 4875 if (cs_ac97_init(card) <= 0) {
5145 if (cs_ac97_init(card) <= 0)
5146 {
5147 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO 4876 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
5148 "cs46xx: cs_ac97_init() failure\n") ); 4877 "cs46xx: cs_ac97_init() failure\n"));
5149 return -EIO; 4878 return -EIO;
5150 } 4879 }
5151 } 4880 } else {
5152 else
5153 {
5154 cs46xx_ac97_resume(card); 4881 cs46xx_ac97_resume(card);
5155 } 4882 }
5156 4883
@@ -5174,23 +4901,17 @@ static int cs_hardware_init(struct cs_card *card)
5174 * If IDLE then Power down the part. We will power components up 4901 * If IDLE then Power down the part. We will power components up
5175 * when we need them. 4902 * when we need them.
5176 */ 4903 */
5177 if(card->pm.flags & CS46XX_PM_IDLE) 4904 if (card->pm.flags & CS46XX_PM_IDLE) {
5178 { 4905 if (!cs_powerdown) {
5179 if(!cs_powerdown) 4906 if ((tmp = cs46xx_powerup(card, CS_POWER_DAC | CS_POWER_ADC |
5180 { 4907 CS_POWER_MIXVON))) {
5181 if( (tmp = cs46xx_powerup(card, CS_POWER_DAC | CS_POWER_ADC |
5182 CS_POWER_MIXVON )) )
5183 {
5184 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO 4908 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
5185 "cs46xx: cs461x_powerup() failure (0x%x)\n",tmp) ); 4909 "cs46xx: cs461x_powerup() failure (0x%x)\n",tmp) );
5186 return -EIO; 4910 return -EIO;
5187 } 4911 }
5188 } 4912 } else {
5189 else 4913 if ((tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC |
5190 { 4914 CS_POWER_MIXVON, CS_FALSE))) {
5191 if( (tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC |
5192 CS_POWER_MIXVON, CS_FALSE )) )
5193 {
5194 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO 4915 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
5195 "cs46xx: cs461x_powerdown() failure (0x%x)\n",tmp) ); 4916 "cs46xx: cs461x_powerdown() failure (0x%x)\n",tmp) );
5196 return -EIO; 4917 return -EIO;
@@ -5310,14 +5031,13 @@ MODULE_AUTHOR("Alan Cox <alan@redhat.com>, Jaroslav Kysela, <pcaudio@crystal.cir
5310MODULE_DESCRIPTION("Crystal SoundFusion Audio Support"); 5031MODULE_DESCRIPTION("Crystal SoundFusion Audio Support");
5311MODULE_LICENSE("GPL"); 5032MODULE_LICENSE("GPL");
5312 5033
5313
5314static const char cs46xx_banner[] = KERN_INFO "Crystal 4280/46xx + AC97 Audio, version " CS46XX_MAJOR_VERSION "." CS46XX_MINOR_VERSION "." CS46XX_ARCH ", " __TIME__ " " __DATE__ "\n"; 5034static const char cs46xx_banner[] = KERN_INFO "Crystal 4280/46xx + AC97 Audio, version " CS46XX_MAJOR_VERSION "." CS46XX_MINOR_VERSION "." CS46XX_ARCH ", " __TIME__ " " __DATE__ "\n";
5315static const char fndmsg[] = KERN_INFO "cs46xx: Found %d audio device(s).\n"; 5035static const char fndmsg[] = KERN_INFO "cs46xx: Found %d audio device(s).\n";
5316 5036
5317static int __devinit cs46xx_probe(struct pci_dev *pci_dev, 5037static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
5318 const struct pci_device_id *pciid) 5038 const struct pci_device_id *pciid)
5319{ 5039{
5320 int i,j; 5040 int i, j;
5321 u16 ss_card, ss_vendor; 5041 u16 ss_card, ss_vendor;
5322 struct cs_card *card; 5042 struct cs_card *card;
5323 dma_addr_t dma_mask; 5043 dma_addr_t dma_mask;
@@ -5378,42 +5098,35 @@ static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
5378 5098
5379 while (cp->name) 5099 while (cp->name)
5380 { 5100 {
5381 if(cp->vendor == ss_vendor && cp->id == ss_card) 5101 if (cp->vendor == ss_vendor && cp->id == ss_card) {
5382 {
5383 card->amplifier_ctrl = cp->amp; 5102 card->amplifier_ctrl = cp->amp;
5384 if(cp->active) 5103 if (cp->active)
5385 card->active_ctrl = cp->active; 5104 card->active_ctrl = cp->active;
5386 if(cp->amp_init) 5105 if (cp->amp_init)
5387 card->amp_init = cp->amp_init; 5106 card->amp_init = cp->amp_init;
5388 break; 5107 break;
5389 } 5108 }
5390 cp++; 5109 cp++;
5391 } 5110 }
5392 if (cp->name==NULL) 5111 if (cp->name == NULL) {
5393 {
5394 printk(KERN_INFO "cs46xx: Unknown card (%04X:%04X) at 0x%08lx/0x%08lx, IRQ %d\n", 5112 printk(KERN_INFO "cs46xx: Unknown card (%04X:%04X) at 0x%08lx/0x%08lx, IRQ %d\n",
5395 ss_vendor, ss_card, card->ba0_addr, card->ba1_addr, card->irq); 5113 ss_vendor, ss_card, card->ba0_addr, card->ba1_addr, card->irq);
5396 } 5114 } else {
5397 else
5398 {
5399 printk(KERN_INFO "cs46xx: %s (%04X:%04X) at 0x%08lx/0x%08lx, IRQ %d\n", 5115 printk(KERN_INFO "cs46xx: %s (%04X:%04X) at 0x%08lx/0x%08lx, IRQ %d\n",
5400 cp->name, ss_vendor, ss_card, card->ba0_addr, card->ba1_addr, card->irq); 5116 cp->name, ss_vendor, ss_card, card->ba0_addr, card->ba1_addr, card->irq);
5401 } 5117 }
5402 5118
5403 if (card->amplifier_ctrl==NULL) 5119 if (card->amplifier_ctrl == NULL) {
5404 {
5405 card->amplifier_ctrl = amp_none; 5120 card->amplifier_ctrl = amp_none;
5406 card->active_ctrl = clkrun_hack; 5121 card->active_ctrl = clkrun_hack;
5407 } 5122 }
5408 5123
5409 if (external_amp == 1) 5124 if (external_amp == 1) {
5410 {
5411 printk(KERN_INFO "cs46xx: Crystal EAPD support forced on.\n"); 5125 printk(KERN_INFO "cs46xx: Crystal EAPD support forced on.\n");
5412 card->amplifier_ctrl = amp_voyetra; 5126 card->amplifier_ctrl = amp_voyetra;
5413 } 5127 }
5414 5128
5415 if (thinkpad == 1) 5129 if (thinkpad == 1) {
5416 {
5417 printk(KERN_INFO "cs46xx: Activating CLKRUN hack for Thinkpad.\n"); 5130 printk(KERN_INFO "cs46xx: Activating CLKRUN hack for Thinkpad.\n");
5418 card->active_ctrl = clkrun_hack; 5131 card->active_ctrl = clkrun_hack;
5419 } 5132 }
@@ -5425,13 +5138,11 @@ static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
5425* and mdelay kernel code is replaced by a pm timer, or the delays 5138* and mdelay kernel code is replaced by a pm timer, or the delays
5426* work well for battery and/or AC power both. 5139* work well for battery and/or AC power both.
5427*/ 5140*/
5428 if(card->active_ctrl == clkrun_hack) 5141 if (card->active_ctrl == clkrun_hack) {
5429 {
5430 initdelay = 2100; 5142 initdelay = 2100;
5431 cs_laptop_wait = 5; 5143 cs_laptop_wait = 5;
5432 } 5144 }
5433 if((card->active_ctrl == clkrun_hack) && !(powerdown == 1)) 5145 if ((card->active_ctrl == clkrun_hack) && !(powerdown == 1)) {
5434 {
5435/* 5146/*
5436* for some currently unknown reason, powering down the DAC and ADC component 5147* for some currently unknown reason, powering down the DAC and ADC component
5437* blocks on thinkpads causes some funky behavior... distoorrrtion and ac97 5148* blocks on thinkpads causes some funky behavior... distoorrrtion and ac97
@@ -5440,7 +5151,7 @@ static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
5440*/ 5151*/
5441 cs_powerdown = 0; 5152 cs_powerdown = 0;
5442 } 5153 }
5443 if(powerdown == 0) 5154 if (powerdown == 0)
5444 cs_powerdown = 0; 5155 cs_powerdown = 0;
5445 card->active_ctrl(card, 1); 5156 card->active_ctrl(card, 1);
5446 5157
@@ -5461,7 +5172,7 @@ static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
5461 card->ba1.name.pmem, 5172 card->ba1.name.pmem,
5462 card->ba1.name.reg) ); 5173 card->ba1.name.reg) );
5463 5174
5464 if(card->ba0 == 0 || card->ba1.name.data0 == 0 || 5175 if (card->ba0 == 0 || card->ba1.name.data0 == 0 ||
5465 card->ba1.name.data1 == 0 || card->ba1.name.pmem == 0 || 5176 card->ba1.name.data1 == 0 || card->ba1.name.pmem == 0 ||
5466 card->ba1.name.reg == 0) 5177 card->ba1.name.reg == 0)
5467 goto fail2; 5178 goto fail2;
@@ -5477,14 +5188,12 @@ static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
5477 } 5188 }
5478 5189
5479 /* register /dev/midi */ 5190 /* register /dev/midi */
5480 if((card->dev_midi = register_sound_midi(&cs_midi_fops, -1)) < 0) 5191 if ((card->dev_midi = register_sound_midi(&cs_midi_fops, -1)) < 0)
5481 printk(KERN_ERR "cs46xx: unable to register midi\n"); 5192 printk(KERN_ERR "cs46xx: unable to register midi\n");
5482 5193
5483 card->pm.flags |= CS46XX_PM_IDLE; 5194 card->pm.flags |= CS46XX_PM_IDLE;
5484 for(i=0;i<5;i++) 5195 for (i = 0; i < 5; i++) {
5485 { 5196 if (cs_hardware_init(card) != 0) {
5486 if (cs_hardware_init(card) != 0)
5487 {
5488 CS_DBGOUT(CS_ERROR, 4, printk( 5197 CS_DBGOUT(CS_ERROR, 4, printk(
5489 "cs46xx: ERROR in cs_hardware_init()... retrying\n")); 5198 "cs46xx: ERROR in cs_hardware_init()... retrying\n"));
5490 for (j = 0; j < NR_AC97; j++) 5199 for (j = 0; j < NR_AC97; j++)
@@ -5497,12 +5206,11 @@ static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
5497 } 5206 }
5498 break; 5207 break;
5499 } 5208 }
5500 if(i>=4) 5209 if(i >= 4) {
5501 {
5502 CS_DBGOUT(CS_PM | CS_ERROR, 1, printk( 5210 CS_DBGOUT(CS_PM | CS_ERROR, 1, printk(
5503 "cs46xx: cs46xx_probe()- cs_hardware_init() failed, retried %d times.\n",i)); 5211 "cs46xx: cs46xx_probe()- cs_hardware_init() failed, retried %d times.\n",i));
5504 unregister_sound_dsp(card->dev_audio); 5212 unregister_sound_dsp(card->dev_audio);
5505 if(card->dev_midi) 5213 if (card->dev_midi)
5506 unregister_sound_midi(card->dev_midi); 5214 unregister_sound_midi(card->dev_midi);
5507 goto fail; 5215 goto fail;
5508 } 5216 }
@@ -5518,7 +5226,7 @@ static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
5518 * Check if we have to init the amplifier, but probably already done 5226 * Check if we have to init the amplifier, but probably already done
5519 * since the CD logic in the ac97 init code will turn on the ext amp. 5227 * since the CD logic in the ac97 init code will turn on the ext amp.
5520 */ 5228 */
5521 if(cp->amp_init) 5229 if (cp->amp_init)
5522 cp->amp_init(card); 5230 cp->amp_init(card);
5523 card->active_ctrl(card, -1); 5231 card->active_ctrl(card, -1);
5524 5232
@@ -5536,15 +5244,15 @@ static int __devinit cs46xx_probe(struct pci_dev *pci_dev,
5536fail: 5244fail:
5537 free_irq(card->irq, card); 5245 free_irq(card->irq, card);
5538fail2: 5246fail2:
5539 if(card->ba0) 5247 if (card->ba0)
5540 iounmap(card->ba0); 5248 iounmap(card->ba0);
5541 if(card->ba1.name.data0) 5249 if (card->ba1.name.data0)
5542 iounmap(card->ba1.name.data0); 5250 iounmap(card->ba1.name.data0);
5543 if(card->ba1.name.data1) 5251 if (card->ba1.name.data1)
5544 iounmap(card->ba1.name.data1); 5252 iounmap(card->ba1.name.data1);
5545 if(card->ba1.name.pmem) 5253 if (card->ba1.name.pmem)
5546 iounmap(card->ba1.name.pmem); 5254 iounmap(card->ba1.name.pmem);
5547 if(card->ba1.name.reg) 5255 if (card->ba1.name.reg)
5548 iounmap(card->ba1.name.reg); 5256 iounmap(card->ba1.name.reg);
5549 kfree(card); 5257 kfree(card);
5550 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_INFO 5258 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_INFO
@@ -5598,9 +5306,8 @@ static void __devexit cs46xx_remove(struct pci_dev *pci_dev)
5598 * Power down the DAC and ADC. We will power them up (if) when we need 5306 * Power down the DAC and ADC. We will power them up (if) when we need
5599 * them. 5307 * them.
5600 */ 5308 */
5601 if( (tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC | 5309 if ((tmp = cs461x_powerdown(card, CS_POWER_DAC | CS_POWER_ADC |
5602 CS_POWER_MIXVON, CS_TRUE )) ) 5310 CS_POWER_MIXVON, CS_TRUE))) {
5603 {
5604 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO 5311 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(KERN_INFO
5605 "cs46xx: cs461x_powerdown() failure (0x%x)\n",tmp) ); 5312 "cs46xx: cs461x_powerdown() failure (0x%x)\n",tmp) );
5606 } 5313 }
@@ -5634,7 +5341,7 @@ static void __devexit cs46xx_remove(struct pci_dev *pci_dev)
5634 ac97_release_codec(card->ac97_codec[i]); 5341 ac97_release_codec(card->ac97_codec[i]);
5635 } 5342 }
5636 unregister_sound_dsp(card->dev_audio); 5343 unregister_sound_dsp(card->dev_audio);
5637 if(card->dev_midi) 5344 if (card->dev_midi)
5638 unregister_sound_midi(card->dev_midi); 5345 unregister_sound_midi(card->dev_midi);
5639 list_del(&card->list); 5346 list_del(&card->list);
5640 kfree(card); 5347 kfree(card);
@@ -5693,8 +5400,7 @@ static int __init cs46xx_init_module(void)
5693 "cs46xx: cs46xx_init_module()+ \n")); 5400 "cs46xx: cs46xx_init_module()+ \n"));
5694 rtn = pci_register_driver(&cs46xx_pci_driver); 5401 rtn = pci_register_driver(&cs46xx_pci_driver);
5695 5402
5696 if(rtn == -ENODEV) 5403 if (rtn == -ENODEV) {
5697 {
5698 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk( 5404 CS_DBGOUT(CS_ERROR | CS_INIT, 1, printk(
5699 "cs46xx: Unable to detect valid cs46xx device\n")); 5405 "cs46xx: Unable to detect valid cs46xx device\n"));
5700 } 5406 }