diff options
-rw-r--r-- | sound/isa/Kconfig | 2 | ||||
-rw-r--r-- | sound/isa/opti9xx/opti92x-ad1848.c | 1110 |
2 files changed, 37 insertions, 1075 deletions
diff --git a/sound/isa/Kconfig b/sound/isa/Kconfig index d649a0e966da..25347a25d63c 100644 --- a/sound/isa/Kconfig +++ b/sound/isa/Kconfig | |||
@@ -304,7 +304,7 @@ config SND_OPTI93X | |||
304 | tristate "OPTi 82C93x" | 304 | tristate "OPTi 82C93x" |
305 | select SND_OPL3_LIB | 305 | select SND_OPL3_LIB |
306 | select SND_MPU401_UART | 306 | select SND_MPU401_UART |
307 | select SND_PCM | 307 | select SND_CS4231_LIB |
308 | help | 308 | help |
309 | Say Y here to include support for soundcards based on Opti | 309 | Say Y here to include support for soundcards based on Opti |
310 | 82C93x chips. | 310 | 82C93x chips. |
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c index fc15b88364b4..41c047e665ec 100644 --- a/sound/isa/opti9xx/opti92x-ad1848.c +++ b/sound/isa/opti9xx/opti92x-ad1848.c | |||
@@ -33,15 +33,10 @@ | |||
33 | #include <asm/io.h> | 33 | #include <asm/io.h> |
34 | #include <asm/dma.h> | 34 | #include <asm/dma.h> |
35 | #include <sound/core.h> | 35 | #include <sound/core.h> |
36 | #ifdef CS4231 | 36 | #if defined(CS4231) || defined(OPTi93X) |
37 | #include <sound/cs4231.h> | 37 | #include <sound/cs4231.h> |
38 | #else | 38 | #else |
39 | #ifndef OPTi93X | ||
40 | #include <sound/ad1848.h> | 39 | #include <sound/ad1848.h> |
41 | #else | ||
42 | #include <sound/control.h> | ||
43 | #include <sound/pcm.h> | ||
44 | #endif /* OPTi93X */ | ||
45 | #endif /* CS4231 */ | 40 | #endif /* CS4231 */ |
46 | #include <sound/mpu401.h> | 41 | #include <sound/mpu401.h> |
47 | #include <sound/opl3.h> | 42 | #include <sound/opl3.h> |
@@ -109,7 +104,6 @@ module_param(dma2, int, 0444); | |||
109 | MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver."); | 104 | MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver."); |
110 | #endif /* CS4231 || OPTi93X */ | 105 | #endif /* CS4231 || OPTi93X */ |
111 | 106 | ||
112 | #define OPTi9XX_HW_DETECT 0 | ||
113 | #define OPTi9XX_HW_82C928 1 | 107 | #define OPTi9XX_HW_82C928 1 |
114 | #define OPTi9XX_HW_82C929 2 | 108 | #define OPTi9XX_HW_82C929 2 |
115 | #define OPTi9XX_HW_82C924 3 | 109 | #define OPTi9XX_HW_82C924 3 |
@@ -123,105 +117,12 @@ MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver."); | |||
123 | 117 | ||
124 | #ifdef OPTi93X | 118 | #ifdef OPTi93X |
125 | 119 | ||
126 | #define OPTi93X_INDEX 0x00 | ||
127 | #define OPTi93X_DATA 0x01 | ||
128 | #define OPTi93X_STATUS 0x02 | 120 | #define OPTi93X_STATUS 0x02 |
129 | #define OPTi93X_DDATA 0x03 | ||
130 | #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r) | 121 | #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r) |
131 | 122 | ||
132 | #define OPTi93X_MIXOUT_LEFT 0x00 | ||
133 | #define OPTi93X_MIXOUT_RIGHT 0x01 | ||
134 | #define OPTi93X_CD_LEFT_INPUT 0x02 | ||
135 | #define OPTi93X_CD_RIGHT_INPUT 0x03 | ||
136 | #define OPTi930_AUX_LEFT_INPUT 0x04 | ||
137 | #define OPTi930_AUX_RIGHT_INPUT 0x05 | ||
138 | #define OPTi931_FM_LEFT_INPUT 0x04 | ||
139 | #define OPTi931_FM_RIGHT_INPUT 0x05 | ||
140 | #define OPTi93X_DAC_LEFT 0x06 | ||
141 | #define OPTi93X_DAC_RIGHT 0x07 | ||
142 | #define OPTi93X_PLAY_FORMAT 0x08 | ||
143 | #define OPTi93X_IFACE_CONF 0x09 | ||
144 | #define OPTi93X_PIN_CTRL 0x0a | ||
145 | #define OPTi93X_ERR_INIT 0x0b | ||
146 | #define OPTi93X_ID 0x0c | ||
147 | #define OPTi93X_PLAY_UPR_CNT 0x0e | ||
148 | #define OPTi93X_PLAY_LWR_CNT 0x0f | ||
149 | #define OPTi931_AUX_LEFT_INPUT 0x10 | ||
150 | #define OPTi931_AUX_RIGHT_INPUT 0x11 | ||
151 | #define OPTi93X_LINE_LEFT_INPUT 0x12 | ||
152 | #define OPTi93X_LINE_RIGHT_INPUT 0x13 | ||
153 | #define OPTi93X_MIC_LEFT_INPUT 0x14 | ||
154 | #define OPTi93X_MIC_RIGHT_INPUT 0x15 | ||
155 | #define OPTi93X_OUT_LEFT 0x16 | ||
156 | #define OPTi93X_OUT_RIGHT 0x17 | ||
157 | #define OPTi93X_CAPT_FORMAT 0x1c | ||
158 | #define OPTi93X_CAPT_UPR_CNT 0x1e | ||
159 | #define OPTi93X_CAPT_LWR_CNT 0x1f | ||
160 | |||
161 | #define OPTi93X_TRD 0x20 | ||
162 | #define OPTi93X_MCE 0x40 | ||
163 | #define OPTi93X_INIT 0x80 | ||
164 | |||
165 | #define OPTi93X_MIXOUT_MIC_GAIN 0x20 | ||
166 | #define OPTi93X_MIXOUT_LINE 0x00 | ||
167 | #define OPTi93X_MIXOUT_CD 0x40 | ||
168 | #define OPTi93X_MIXOUT_MIC 0x80 | ||
169 | #define OPTi93X_MIXOUT_MIXER 0xc0 | ||
170 | |||
171 | #define OPTi93X_STEREO 0x10 | ||
172 | #define OPTi93X_LINEAR_8 0x00 | ||
173 | #define OPTi93X_ULAW_8 0x20 | ||
174 | #define OPTi93X_LINEAR_16_LIT 0x40 | ||
175 | #define OPTi93X_ALAW_8 0x60 | ||
176 | #define OPTi93X_ADPCM_16 0xa0 | ||
177 | #define OPTi93X_LINEAR_16_BIG 0xc0 | ||
178 | |||
179 | #define OPTi93X_CAPTURE_PIO 0x80 | ||
180 | #define OPTi93X_PLAYBACK_PIO 0x40 | ||
181 | #define OPTi93X_AUTOCALIB 0x08 | ||
182 | #define OPTi93X_SINGLE_DMA 0x04 | ||
183 | #define OPTi93X_CAPTURE_ENABLE 0x02 | ||
184 | #define OPTi93X_PLAYBACK_ENABLE 0x01 | ||
185 | |||
186 | #define OPTi93X_IRQ_ENABLE 0x02 | ||
187 | |||
188 | #define OPTi93X_DMA_REQUEST 0x10 | ||
189 | #define OPTi93X_CALIB_IN_PROGRESS 0x20 | ||
190 | |||
191 | #define OPTi93X_IRQ_PLAYBACK 0x04 | 123 | #define OPTi93X_IRQ_PLAYBACK 0x04 |
192 | #define OPTi93X_IRQ_CAPTURE 0x08 | 124 | #define OPTi93X_IRQ_CAPTURE 0x08 |
193 | 125 | ||
194 | |||
195 | struct snd_opti93x { | ||
196 | unsigned long port; | ||
197 | struct resource *res_port; | ||
198 | int irq; | ||
199 | int dma1; | ||
200 | int dma2; | ||
201 | |||
202 | struct snd_opti9xx *chip; | ||
203 | unsigned short hardware; | ||
204 | unsigned char image[32]; | ||
205 | |||
206 | unsigned char mce_bit; | ||
207 | unsigned short mode; | ||
208 | int mute; | ||
209 | |||
210 | spinlock_t lock; | ||
211 | |||
212 | struct snd_card *card; | ||
213 | struct snd_pcm *pcm; | ||
214 | struct snd_pcm_substream *playback_substream; | ||
215 | struct snd_pcm_substream *capture_substream; | ||
216 | unsigned int p_dma_size; | ||
217 | unsigned int c_dma_size; | ||
218 | }; | ||
219 | |||
220 | #define OPTi93X_MODE_NONE 0x00 | ||
221 | #define OPTi93X_MODE_PLAY 0x01 | ||
222 | #define OPTi93X_MODE_CAPTURE 0x02 | ||
223 | #define OPTi93X_MODE_OPEN (OPTi93X_MODE_PLAY | OPTi93X_MODE_CAPTURE) | ||
224 | |||
225 | #endif /* OPTi93X */ | 126 | #endif /* OPTi93X */ |
226 | 127 | ||
227 | struct snd_opti9xx { | 128 | struct snd_opti9xx { |
@@ -234,6 +135,7 @@ struct snd_opti9xx { | |||
234 | unsigned long mc_base_size; | 135 | unsigned long mc_base_size; |
235 | #ifdef OPTi93X | 136 | #ifdef OPTi93X |
236 | unsigned long mc_indir_index; | 137 | unsigned long mc_indir_index; |
138 | struct snd_cs4231 *codec; | ||
237 | #endif /* OPTi93X */ | 139 | #endif /* OPTi93X */ |
238 | unsigned long pwd_reg; | 140 | unsigned long pwd_reg; |
239 | 141 | ||
@@ -654,979 +556,23 @@ __skip_mpu: | |||
654 | 556 | ||
655 | #ifdef OPTi93X | 557 | #ifdef OPTi93X |
656 | 558 | ||
657 | static unsigned char snd_opti93x_default_image[32] = | ||
658 | { | ||
659 | 0x00, /* 00/00 - l_mixout_outctrl */ | ||
660 | 0x00, /* 01/01 - r_mixout_outctrl */ | ||
661 | 0x88, /* 02/02 - l_cd_inctrl */ | ||
662 | 0x88, /* 03/03 - r_cd_inctrl */ | ||
663 | 0x88, /* 04/04 - l_a1/fm_inctrl */ | ||
664 | 0x88, /* 05/05 - r_a1/fm_inctrl */ | ||
665 | 0x80, /* 06/06 - l_dac_inctrl */ | ||
666 | 0x80, /* 07/07 - r_dac_inctrl */ | ||
667 | 0x00, /* 08/08 - ply_dataform_reg */ | ||
668 | 0x00, /* 09/09 - if_conf */ | ||
669 | 0x00, /* 0a/10 - pin_ctrl */ | ||
670 | 0x00, /* 0b/11 - err_init_reg */ | ||
671 | 0x0a, /* 0c/12 - id_reg */ | ||
672 | 0x00, /* 0d/13 - reserved */ | ||
673 | 0x00, /* 0e/14 - ply_upcount_reg */ | ||
674 | 0x00, /* 0f/15 - ply_lowcount_reg */ | ||
675 | 0x88, /* 10/16 - reserved/l_a1_inctrl */ | ||
676 | 0x88, /* 11/17 - reserved/r_a1_inctrl */ | ||
677 | 0x88, /* 12/18 - l_line_inctrl */ | ||
678 | 0x88, /* 13/19 - r_line_inctrl */ | ||
679 | 0x88, /* 14/20 - l_mic_inctrl */ | ||
680 | 0x88, /* 15/21 - r_mic_inctrl */ | ||
681 | 0x80, /* 16/22 - l_out_outctrl */ | ||
682 | 0x80, /* 17/23 - r_out_outctrl */ | ||
683 | 0x00, /* 18/24 - reserved */ | ||
684 | 0x00, /* 19/25 - reserved */ | ||
685 | 0x00, /* 1a/26 - reserved */ | ||
686 | 0x00, /* 1b/27 - reserved */ | ||
687 | 0x00, /* 1c/28 - cap_dataform_reg */ | ||
688 | 0x00, /* 1d/29 - reserved */ | ||
689 | 0x00, /* 1e/30 - cap_upcount_reg */ | ||
690 | 0x00 /* 1f/31 - cap_lowcount_reg */ | ||
691 | }; | ||
692 | |||
693 | |||
694 | static int snd_opti93x_busy_wait(struct snd_opti93x *chip) | ||
695 | { | ||
696 | int timeout; | ||
697 | |||
698 | for (timeout = 250; timeout-- > 0; udelay(10)) | ||
699 | if (!(inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_INIT)) | ||
700 | return 0; | ||
701 | |||
702 | snd_printk("chip still busy.\n"); | ||
703 | return -EBUSY; | ||
704 | } | ||
705 | |||
706 | static unsigned char snd_opti93x_in(struct snd_opti93x *chip, unsigned char reg) | ||
707 | { | ||
708 | snd_opti93x_busy_wait(chip); | ||
709 | outb(chip->mce_bit | (reg & 0x1f), OPTi93X_PORT(chip, INDEX)); | ||
710 | return inb(OPTi93X_PORT(chip, DATA)); | ||
711 | } | ||
712 | |||
713 | static void snd_opti93x_out(struct snd_opti93x *chip, unsigned char reg, | ||
714 | unsigned char value) | ||
715 | { | ||
716 | snd_opti93x_busy_wait(chip); | ||
717 | outb(chip->mce_bit | (reg & 0x1f), OPTi93X_PORT(chip, INDEX)); | ||
718 | outb(value, OPTi93X_PORT(chip, DATA)); | ||
719 | } | ||
720 | |||
721 | static void snd_opti93x_out_image(struct snd_opti93x *chip, unsigned char reg, | ||
722 | unsigned char value) | ||
723 | { | ||
724 | snd_opti93x_out(chip, reg, chip->image[reg] = value); | ||
725 | } | ||
726 | |||
727 | static void snd_opti93x_out_mask(struct snd_opti93x *chip, unsigned char reg, | ||
728 | unsigned char mask, unsigned char value) | ||
729 | { | ||
730 | snd_opti93x_out_image(chip, reg, | ||
731 | (chip->image[reg] & ~mask) | (value & mask)); | ||
732 | } | ||
733 | |||
734 | |||
735 | static void snd_opti93x_mce_up(struct snd_opti93x *chip) | ||
736 | { | ||
737 | snd_opti93x_busy_wait(chip); | ||
738 | |||
739 | chip->mce_bit = OPTi93X_MCE; | ||
740 | if (!(inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_MCE)) | ||
741 | outb(chip->mce_bit, OPTi93X_PORT(chip, INDEX)); | ||
742 | } | ||
743 | |||
744 | static void snd_opti93x_mce_down(struct snd_opti93x *chip) | ||
745 | { | ||
746 | snd_opti93x_busy_wait(chip); | ||
747 | |||
748 | chip->mce_bit = 0; | ||
749 | if (inb(OPTi93X_PORT(chip, INDEX)) & OPTi93X_MCE) | ||
750 | outb(chip->mce_bit, OPTi93X_PORT(chip, INDEX)); | ||
751 | } | ||
752 | |||
753 | #define snd_opti93x_mute_reg(chip, reg, mute) \ | ||
754 | snd_opti93x_out(chip, reg, mute ? 0x80 : chip->image[reg]); | ||
755 | |||
756 | static void snd_opti93x_mute(struct snd_opti93x *chip, int mute) | ||
757 | { | ||
758 | mute = mute ? 1 : 0; | ||
759 | if (chip->mute == mute) | ||
760 | return; | ||
761 | |||
762 | chip->mute = mute; | ||
763 | |||
764 | snd_opti93x_mute_reg(chip, OPTi93X_CD_LEFT_INPUT, mute); | ||
765 | snd_opti93x_mute_reg(chip, OPTi93X_CD_RIGHT_INPUT, mute); | ||
766 | switch (chip->hardware) { | ||
767 | case OPTi9XX_HW_82C930: | ||
768 | snd_opti93x_mute_reg(chip, OPTi930_AUX_LEFT_INPUT, mute); | ||
769 | snd_opti93x_mute_reg(chip, OPTi930_AUX_RIGHT_INPUT, mute); | ||
770 | break; | ||
771 | case OPTi9XX_HW_82C931: | ||
772 | case OPTi9XX_HW_82C933: | ||
773 | snd_opti93x_mute_reg(chip, OPTi931_FM_LEFT_INPUT, mute); | ||
774 | snd_opti93x_mute_reg(chip, OPTi931_FM_RIGHT_INPUT, mute); | ||
775 | snd_opti93x_mute_reg(chip, OPTi931_AUX_LEFT_INPUT, mute); | ||
776 | snd_opti93x_mute_reg(chip, OPTi931_AUX_RIGHT_INPUT, mute); | ||
777 | } | ||
778 | snd_opti93x_mute_reg(chip, OPTi93X_DAC_LEFT, mute); | ||
779 | snd_opti93x_mute_reg(chip, OPTi93X_DAC_RIGHT, mute); | ||
780 | snd_opti93x_mute_reg(chip, OPTi93X_LINE_LEFT_INPUT, mute); | ||
781 | snd_opti93x_mute_reg(chip, OPTi93X_LINE_RIGHT_INPUT, mute); | ||
782 | snd_opti93x_mute_reg(chip, OPTi93X_MIC_LEFT_INPUT, mute); | ||
783 | snd_opti93x_mute_reg(chip, OPTi93X_MIC_RIGHT_INPUT, mute); | ||
784 | snd_opti93x_mute_reg(chip, OPTi93X_OUT_LEFT, mute); | ||
785 | snd_opti93x_mute_reg(chip, OPTi93X_OUT_RIGHT, mute); | ||
786 | } | ||
787 | |||
788 | |||
789 | static unsigned int snd_opti93x_get_count(unsigned char format, | ||
790 | unsigned int size) | ||
791 | { | ||
792 | switch (format & 0xe0) { | ||
793 | case OPTi93X_LINEAR_16_LIT: | ||
794 | case OPTi93X_LINEAR_16_BIG: | ||
795 | size >>= 1; | ||
796 | break; | ||
797 | case OPTi93X_ADPCM_16: | ||
798 | return size >> 2; | ||
799 | } | ||
800 | return (format & OPTi93X_STEREO) ? (size >> 1) : size; | ||
801 | } | ||
802 | |||
803 | static unsigned int rates[] = { 5512, 6615, 8000, 9600, 11025, 16000, | ||
804 | 18900, 22050, 27428, 32000, 33075, 37800, | ||
805 | 44100, 48000 }; | ||
806 | #define RATES ARRAY_SIZE(rates) | ||
807 | |||
808 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { | ||
809 | .count = RATES, | ||
810 | .list = rates, | ||
811 | .mask = 0, | ||
812 | }; | ||
813 | |||
814 | static unsigned char bits[] = { 0x01, 0x0f, 0x00, 0x0e, 0x03, 0x02, | ||
815 | 0x05, 0x07, 0x04, 0x06, 0x0d, 0x09, | ||
816 | 0x0b, 0x0c}; | ||
817 | |||
818 | static unsigned char snd_opti93x_get_freq(unsigned int rate) | ||
819 | { | ||
820 | unsigned int i; | ||
821 | |||
822 | for (i = 0; i < RATES; i++) { | ||
823 | if (rate == rates[i]) | ||
824 | return bits[i]; | ||
825 | } | ||
826 | snd_BUG(); | ||
827 | return bits[RATES-1]; | ||
828 | } | ||
829 | |||
830 | static unsigned char snd_opti93x_get_format(struct snd_opti93x *chip, | ||
831 | unsigned int format, int channels) | ||
832 | { | ||
833 | unsigned char retval = OPTi93X_LINEAR_8; | ||
834 | |||
835 | switch (format) { | ||
836 | case SNDRV_PCM_FORMAT_MU_LAW: | ||
837 | retval = OPTi93X_ULAW_8; | ||
838 | break; | ||
839 | case SNDRV_PCM_FORMAT_A_LAW: | ||
840 | retval = OPTi93X_ALAW_8; | ||
841 | break; | ||
842 | case SNDRV_PCM_FORMAT_S16_LE: | ||
843 | retval = OPTi93X_LINEAR_16_LIT; | ||
844 | break; | ||
845 | case SNDRV_PCM_FORMAT_S16_BE: | ||
846 | retval = OPTi93X_LINEAR_16_BIG; | ||
847 | break; | ||
848 | case SNDRV_PCM_FORMAT_IMA_ADPCM: | ||
849 | retval = OPTi93X_ADPCM_16; | ||
850 | } | ||
851 | return (channels > 1) ? (retval | OPTi93X_STEREO) : retval; | ||
852 | } | ||
853 | |||
854 | |||
855 | static void snd_opti93x_playback_format(struct snd_opti93x *chip, unsigned char fmt) | ||
856 | { | ||
857 | unsigned char mask; | ||
858 | |||
859 | snd_opti93x_mute(chip, 1); | ||
860 | |||
861 | snd_opti93x_mce_up(chip); | ||
862 | mask = (chip->mode & OPTi93X_MODE_CAPTURE) ? 0xf0 : 0xff; | ||
863 | snd_opti93x_out_mask(chip, OPTi93X_PLAY_FORMAT, mask, fmt); | ||
864 | snd_opti93x_mce_down(chip); | ||
865 | |||
866 | snd_opti93x_mute(chip, 0); | ||
867 | } | ||
868 | |||
869 | static void snd_opti93x_capture_format(struct snd_opti93x *chip, unsigned char fmt) | ||
870 | { | ||
871 | snd_opti93x_mute(chip, 1); | ||
872 | |||
873 | snd_opti93x_mce_up(chip); | ||
874 | if (!(chip->mode & OPTi93X_MODE_PLAY)) | ||
875 | snd_opti93x_out_mask(chip, OPTi93X_PLAY_FORMAT, 0x0f, fmt); | ||
876 | else | ||
877 | fmt = chip->image[OPTi93X_PLAY_FORMAT] & 0xf0; | ||
878 | snd_opti93x_out_image(chip, OPTi93X_CAPT_FORMAT, fmt); | ||
879 | snd_opti93x_mce_down(chip); | ||
880 | |||
881 | snd_opti93x_mute(chip, 0); | ||
882 | } | ||
883 | |||
884 | |||
885 | static int snd_opti93x_open(struct snd_opti93x *chip, unsigned int mode) | ||
886 | { | ||
887 | unsigned long flags; | ||
888 | |||
889 | spin_lock_irqsave(&chip->lock, flags); | ||
890 | |||
891 | if (chip->mode & mode) { | ||
892 | spin_unlock_irqrestore(&chip->lock, flags); | ||
893 | return -EAGAIN; | ||
894 | } | ||
895 | |||
896 | if (!(chip->mode & OPTi93X_MODE_OPEN)) { | ||
897 | outb(0x00, OPTi93X_PORT(chip, STATUS)); | ||
898 | snd_opti93x_out_mask(chip, OPTi93X_PIN_CTRL, | ||
899 | OPTi93X_IRQ_ENABLE, OPTi93X_IRQ_ENABLE); | ||
900 | chip->mode = mode; | ||
901 | } | ||
902 | else | ||
903 | chip->mode |= mode; | ||
904 | |||
905 | spin_unlock_irqrestore(&chip->lock, flags); | ||
906 | return 0; | ||
907 | } | ||
908 | |||
909 | static void snd_opti93x_close(struct snd_opti93x *chip, unsigned int mode) | ||
910 | { | ||
911 | unsigned long flags; | ||
912 | |||
913 | spin_lock_irqsave(&chip->lock, flags); | ||
914 | |||
915 | chip->mode &= ~mode; | ||
916 | if (chip->mode & OPTi93X_MODE_OPEN) { | ||
917 | spin_unlock_irqrestore(&chip->lock, flags); | ||
918 | return; | ||
919 | } | ||
920 | |||
921 | snd_opti93x_mute(chip, 1); | ||
922 | |||
923 | outb(0, OPTi93X_PORT(chip, STATUS)); | ||
924 | snd_opti93x_out_mask(chip, OPTi93X_PIN_CTRL, OPTi93X_IRQ_ENABLE, | ||
925 | ~OPTi93X_IRQ_ENABLE); | ||
926 | |||
927 | snd_opti93x_mce_up(chip); | ||
928 | snd_opti93x_out_image(chip, OPTi93X_IFACE_CONF, 0x00); | ||
929 | snd_opti93x_mce_down(chip); | ||
930 | chip->mode = 0; | ||
931 | |||
932 | snd_opti93x_mute(chip, 0); | ||
933 | spin_unlock_irqrestore(&chip->lock, flags); | ||
934 | } | ||
935 | |||
936 | static int snd_opti93x_trigger(struct snd_pcm_substream *substream, | ||
937 | unsigned char what, int cmd) | ||
938 | { | ||
939 | struct snd_opti93x *chip = snd_pcm_substream_chip(substream); | ||
940 | |||
941 | switch (cmd) { | ||
942 | case SNDRV_PCM_TRIGGER_START: | ||
943 | case SNDRV_PCM_TRIGGER_STOP: | ||
944 | { | ||
945 | unsigned int what = 0; | ||
946 | struct snd_pcm_substream *s; | ||
947 | snd_pcm_group_for_each_entry(s, substream) { | ||
948 | if (s == chip->playback_substream) { | ||
949 | what |= OPTi93X_PLAYBACK_ENABLE; | ||
950 | snd_pcm_trigger_done(s, substream); | ||
951 | } else if (s == chip->capture_substream) { | ||
952 | what |= OPTi93X_CAPTURE_ENABLE; | ||
953 | snd_pcm_trigger_done(s, substream); | ||
954 | } | ||
955 | } | ||
956 | spin_lock(&chip->lock); | ||
957 | if (cmd == SNDRV_PCM_TRIGGER_START) { | ||
958 | snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, what, what); | ||
959 | if (what & OPTi93X_CAPTURE_ENABLE) | ||
960 | udelay(50); | ||
961 | } else | ||
962 | snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, what, 0x00); | ||
963 | spin_unlock(&chip->lock); | ||
964 | break; | ||
965 | } | ||
966 | default: | ||
967 | return -EINVAL; | ||
968 | } | ||
969 | return 0; | ||
970 | } | ||
971 | |||
972 | static int snd_opti93x_playback_trigger(struct snd_pcm_substream *substream, int cmd) | ||
973 | { | ||
974 | return snd_opti93x_trigger(substream, | ||
975 | OPTi93X_PLAYBACK_ENABLE, cmd); | ||
976 | } | ||
977 | |||
978 | static int snd_opti93x_capture_trigger(struct snd_pcm_substream *substream, int cmd) | ||
979 | { | ||
980 | return snd_opti93x_trigger(substream, | ||
981 | OPTi93X_CAPTURE_ENABLE, cmd); | ||
982 | } | ||
983 | |||
984 | static int snd_opti93x_hw_params(struct snd_pcm_substream *substream, | ||
985 | struct snd_pcm_hw_params *hw_params) | ||
986 | { | ||
987 | return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); | ||
988 | } | ||
989 | |||
990 | |||
991 | static int snd_opti93x_hw_free(struct snd_pcm_substream *substream) | ||
992 | { | ||
993 | snd_pcm_lib_free_pages(substream); | ||
994 | return 0; | ||
995 | } | ||
996 | |||
997 | |||
998 | static int snd_opti93x_playback_prepare(struct snd_pcm_substream *substream) | ||
999 | { | ||
1000 | struct snd_opti93x *chip = snd_pcm_substream_chip(substream); | ||
1001 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
1002 | unsigned long flags; | ||
1003 | unsigned char format; | ||
1004 | unsigned int count = snd_pcm_lib_period_bytes(substream); | ||
1005 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); | ||
1006 | |||
1007 | spin_lock_irqsave(&chip->lock, flags); | ||
1008 | |||
1009 | chip->p_dma_size = size; | ||
1010 | snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, | ||
1011 | OPTi93X_PLAYBACK_ENABLE | OPTi93X_PLAYBACK_PIO, | ||
1012 | ~(OPTi93X_PLAYBACK_ENABLE | OPTi93X_PLAYBACK_PIO)); | ||
1013 | |||
1014 | snd_dma_program(chip->dma1, runtime->dma_addr, size, | ||
1015 | DMA_MODE_WRITE | DMA_AUTOINIT); | ||
1016 | |||
1017 | format = snd_opti93x_get_freq(runtime->rate); | ||
1018 | format |= snd_opti93x_get_format(chip, runtime->format, | ||
1019 | runtime->channels); | ||
1020 | snd_opti93x_playback_format(chip, format); | ||
1021 | format = chip->image[OPTi93X_PLAY_FORMAT]; | ||
1022 | |||
1023 | count = snd_opti93x_get_count(format, count) - 1; | ||
1024 | snd_opti93x_out_image(chip, OPTi93X_PLAY_LWR_CNT, count); | ||
1025 | snd_opti93x_out_image(chip, OPTi93X_PLAY_UPR_CNT, count >> 8); | ||
1026 | |||
1027 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1028 | return 0; | ||
1029 | } | ||
1030 | |||
1031 | static int snd_opti93x_capture_prepare(struct snd_pcm_substream *substream) | ||
1032 | { | ||
1033 | struct snd_opti93x *chip = snd_pcm_substream_chip(substream); | ||
1034 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
1035 | unsigned long flags; | ||
1036 | unsigned char format; | ||
1037 | unsigned int count = snd_pcm_lib_period_bytes(substream); | ||
1038 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); | ||
1039 | |||
1040 | spin_lock_irqsave(&chip->lock, flags); | ||
1041 | |||
1042 | chip->c_dma_size = size; | ||
1043 | snd_opti93x_out_mask(chip, OPTi93X_IFACE_CONF, | ||
1044 | OPTi93X_CAPTURE_ENABLE | OPTi93X_CAPTURE_PIO, 0); | ||
1045 | |||
1046 | snd_dma_program(chip->dma2, runtime->dma_addr, size, | ||
1047 | DMA_MODE_READ | DMA_AUTOINIT); | ||
1048 | |||
1049 | format = snd_opti93x_get_freq(runtime->rate); | ||
1050 | format |= snd_opti93x_get_format(chip, runtime->format, | ||
1051 | runtime->channels); | ||
1052 | snd_opti93x_capture_format(chip, format); | ||
1053 | format = chip->image[OPTi93X_CAPT_FORMAT]; | ||
1054 | |||
1055 | count = snd_opti93x_get_count(format, count) - 1; | ||
1056 | snd_opti93x_out_image(chip, OPTi93X_CAPT_LWR_CNT, count); | ||
1057 | snd_opti93x_out_image(chip, OPTi93X_CAPT_UPR_CNT, count >> 8); | ||
1058 | |||
1059 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1060 | return 0; | ||
1061 | } | ||
1062 | |||
1063 | static snd_pcm_uframes_t snd_opti93x_playback_pointer(struct snd_pcm_substream *substream) | ||
1064 | { | ||
1065 | struct snd_opti93x *chip = snd_pcm_substream_chip(substream); | ||
1066 | size_t ptr; | ||
1067 | |||
1068 | if (!(chip->image[OPTi93X_IFACE_CONF] & OPTi93X_PLAYBACK_ENABLE)) | ||
1069 | return 0; | ||
1070 | |||
1071 | ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size); | ||
1072 | return bytes_to_frames(substream->runtime, ptr); | ||
1073 | } | ||
1074 | |||
1075 | static snd_pcm_uframes_t snd_opti93x_capture_pointer(struct snd_pcm_substream *substream) | ||
1076 | { | ||
1077 | struct snd_opti93x *chip = snd_pcm_substream_chip(substream); | ||
1078 | size_t ptr; | ||
1079 | |||
1080 | if (!(chip->image[OPTi93X_IFACE_CONF] & OPTi93X_CAPTURE_ENABLE)) | ||
1081 | return 0; | ||
1082 | |||
1083 | ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size); | ||
1084 | return bytes_to_frames(substream->runtime, ptr); | ||
1085 | } | ||
1086 | |||
1087 | |||
1088 | static void snd_opti93x_overrange(struct snd_opti93x *chip) | ||
1089 | { | ||
1090 | unsigned long flags; | ||
1091 | |||
1092 | spin_lock_irqsave(&chip->lock, flags); | ||
1093 | |||
1094 | if (snd_opti93x_in(chip, OPTi93X_ERR_INIT) & (0x08 | 0x02)) | ||
1095 | chip->capture_substream->runtime->overrange++; | ||
1096 | |||
1097 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1098 | } | ||
1099 | |||
1100 | static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id) | 559 | static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id) |
1101 | { | 560 | { |
1102 | struct snd_opti93x *codec = dev_id; | 561 | struct snd_cs4231 *codec = dev_id; |
562 | struct snd_opti9xx *chip = codec->card->private_data; | ||
1103 | unsigned char status; | 563 | unsigned char status; |
1104 | 564 | ||
1105 | status = snd_opti9xx_read(codec->chip, OPTi9XX_MC_REG(11)); | 565 | status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11)); |
1106 | if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream) | 566 | if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream) |
1107 | snd_pcm_period_elapsed(codec->playback_substream); | 567 | snd_pcm_period_elapsed(codec->playback_substream); |
1108 | if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) { | 568 | if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) { |
1109 | snd_opti93x_overrange(codec); | 569 | snd_cs4231_overrange(codec); |
1110 | snd_pcm_period_elapsed(codec->capture_substream); | 570 | snd_pcm_period_elapsed(codec->capture_substream); |
1111 | } | 571 | } |
1112 | outb(0x00, OPTi93X_PORT(codec, STATUS)); | 572 | outb(0x00, OPTi93X_PORT(codec, STATUS)); |
1113 | return IRQ_HANDLED; | 573 | return IRQ_HANDLED; |
1114 | } | 574 | } |
1115 | 575 | ||
1116 | |||
1117 | static struct snd_pcm_hardware snd_opti93x_playback = { | ||
1118 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | | ||
1119 | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START), | ||
1120 | .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM | | ||
1121 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE), | ||
1122 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, | ||
1123 | .rate_min = 5512, | ||
1124 | .rate_max = 48000, | ||
1125 | .channels_min = 1, | ||
1126 | .channels_max = 2, | ||
1127 | .buffer_bytes_max = (128*1024), | ||
1128 | .period_bytes_min = 64, | ||
1129 | .period_bytes_max = (128*1024), | ||
1130 | .periods_min = 1, | ||
1131 | .periods_max = 1024, | ||
1132 | .fifo_size = 0, | ||
1133 | }; | ||
1134 | |||
1135 | static struct snd_pcm_hardware snd_opti93x_capture = { | ||
1136 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | | ||
1137 | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START), | ||
1138 | .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM | | ||
1139 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE), | ||
1140 | .rates = SNDRV_PCM_RATE_8000_48000, | ||
1141 | .rate_min = 5512, | ||
1142 | .rate_max = 48000, | ||
1143 | .channels_min = 1, | ||
1144 | .channels_max = 2, | ||
1145 | .buffer_bytes_max = (128*1024), | ||
1146 | .period_bytes_min = 64, | ||
1147 | .period_bytes_max = (128*1024), | ||
1148 | .periods_min = 1, | ||
1149 | .periods_max = 1024, | ||
1150 | .fifo_size = 0, | ||
1151 | }; | ||
1152 | |||
1153 | static int snd_opti93x_playback_open(struct snd_pcm_substream *substream) | ||
1154 | { | ||
1155 | int error; | ||
1156 | struct snd_opti93x *chip = snd_pcm_substream_chip(substream); | ||
1157 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
1158 | |||
1159 | if ((error = snd_opti93x_open(chip, OPTi93X_MODE_PLAY)) < 0) | ||
1160 | return error; | ||
1161 | snd_pcm_set_sync(substream); | ||
1162 | chip->playback_substream = substream; | ||
1163 | runtime->hw = snd_opti93x_playback; | ||
1164 | snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max); | ||
1165 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); | ||
1166 | return error; | ||
1167 | } | ||
1168 | |||
1169 | static int snd_opti93x_capture_open(struct snd_pcm_substream *substream) | ||
1170 | { | ||
1171 | int error; | ||
1172 | struct snd_opti93x *chip = snd_pcm_substream_chip(substream); | ||
1173 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
1174 | |||
1175 | if ((error = snd_opti93x_open(chip, OPTi93X_MODE_CAPTURE)) < 0) | ||
1176 | return error; | ||
1177 | runtime->hw = snd_opti93x_capture; | ||
1178 | snd_pcm_set_sync(substream); | ||
1179 | chip->capture_substream = substream; | ||
1180 | snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max); | ||
1181 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); | ||
1182 | return error; | ||
1183 | } | ||
1184 | |||
1185 | static int snd_opti93x_playback_close(struct snd_pcm_substream *substream) | ||
1186 | { | ||
1187 | struct snd_opti93x *chip = snd_pcm_substream_chip(substream); | ||
1188 | |||
1189 | chip->playback_substream = NULL; | ||
1190 | snd_opti93x_close(chip, OPTi93X_MODE_PLAY); | ||
1191 | return 0; | ||
1192 | } | ||
1193 | |||
1194 | static int snd_opti93x_capture_close(struct snd_pcm_substream *substream) | ||
1195 | { | ||
1196 | struct snd_opti93x *chip = snd_pcm_substream_chip(substream); | ||
1197 | |||
1198 | chip->capture_substream = NULL; | ||
1199 | snd_opti93x_close(chip, OPTi93X_MODE_CAPTURE); | ||
1200 | return 0; | ||
1201 | } | ||
1202 | |||
1203 | |||
1204 | static void snd_opti93x_init(struct snd_opti93x *chip) | ||
1205 | { | ||
1206 | unsigned long flags; | ||
1207 | int i; | ||
1208 | |||
1209 | spin_lock_irqsave(&chip->lock, flags); | ||
1210 | snd_opti93x_mce_up(chip); | ||
1211 | |||
1212 | for (i = 0; i < 32; i++) | ||
1213 | snd_opti93x_out_image(chip, i, snd_opti93x_default_image[i]); | ||
1214 | |||
1215 | snd_opti93x_mce_down(chip); | ||
1216 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1217 | } | ||
1218 | |||
1219 | static int snd_opti93x_probe(struct snd_opti93x *chip) | ||
1220 | { | ||
1221 | unsigned long flags; | ||
1222 | unsigned char val; | ||
1223 | |||
1224 | spin_lock_irqsave(&chip->lock, flags); | ||
1225 | val = snd_opti93x_in(chip, OPTi93X_ID) & 0x0f; | ||
1226 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1227 | |||
1228 | return (val == 0x0a) ? 0 : -ENODEV; | ||
1229 | } | ||
1230 | |||
1231 | static int snd_opti93x_free(struct snd_opti93x *chip) | ||
1232 | { | ||
1233 | release_and_free_resource(chip->res_port); | ||
1234 | if (chip->dma1 >= 0) { | ||
1235 | disable_dma(chip->dma1); | ||
1236 | free_dma(chip->dma1); | ||
1237 | } | ||
1238 | if (chip->dma2 >= 0) { | ||
1239 | disable_dma(chip->dma2); | ||
1240 | free_dma(chip->dma2); | ||
1241 | } | ||
1242 | if (chip->irq >= 0) { | ||
1243 | free_irq(chip->irq, chip); | ||
1244 | } | ||
1245 | kfree(chip); | ||
1246 | return 0; | ||
1247 | } | ||
1248 | |||
1249 | static int snd_opti93x_dev_free(struct snd_device *device) | ||
1250 | { | ||
1251 | struct snd_opti93x *chip = device->device_data; | ||
1252 | return snd_opti93x_free(chip); | ||
1253 | } | ||
1254 | |||
1255 | static const char *snd_opti93x_chip_id(struct snd_opti93x *codec) | ||
1256 | { | ||
1257 | switch (codec->hardware) { | ||
1258 | case OPTi9XX_HW_82C930: return "82C930"; | ||
1259 | case OPTi9XX_HW_82C931: return "82C931"; | ||
1260 | case OPTi9XX_HW_82C933: return "82C933"; | ||
1261 | default: return "???"; | ||
1262 | } | ||
1263 | } | ||
1264 | |||
1265 | static int snd_opti93x_create(struct snd_card *card, struct snd_opti9xx *chip, | ||
1266 | int dma1, int dma2, | ||
1267 | struct snd_opti93x **rcodec) | ||
1268 | { | ||
1269 | static struct snd_device_ops ops = { | ||
1270 | .dev_free = snd_opti93x_dev_free, | ||
1271 | }; | ||
1272 | int error; | ||
1273 | struct snd_opti93x *codec; | ||
1274 | |||
1275 | *rcodec = NULL; | ||
1276 | codec = kzalloc(sizeof(*codec), GFP_KERNEL); | ||
1277 | if (codec == NULL) | ||
1278 | return -ENOMEM; | ||
1279 | codec->irq = -1; | ||
1280 | codec->dma1 = -1; | ||
1281 | codec->dma2 = -1; | ||
1282 | |||
1283 | if ((codec->res_port = request_region(chip->wss_base + 4, 4, "OPTI93x CODEC")) == NULL) { | ||
1284 | snd_printk(KERN_ERR "opti9xx: can't grab port 0x%lx\n", chip->wss_base + 4); | ||
1285 | snd_opti93x_free(codec); | ||
1286 | return -EBUSY; | ||
1287 | } | ||
1288 | if (request_dma(dma1, "OPTI93x - 1")) { | ||
1289 | snd_printk(KERN_ERR "opti9xx: can't grab DMA1 %d\n", dma1); | ||
1290 | snd_opti93x_free(codec); | ||
1291 | return -EBUSY; | ||
1292 | } | ||
1293 | codec->dma1 = chip->dma1; | ||
1294 | if (request_dma(dma2, "OPTI93x - 2")) { | ||
1295 | snd_printk(KERN_ERR "opti9xx: can't grab DMA2 %d\n", dma2); | ||
1296 | snd_opti93x_free(codec); | ||
1297 | return -EBUSY; | ||
1298 | } | ||
1299 | codec->dma2 = chip->dma2; | ||
1300 | |||
1301 | if (request_irq(chip->irq, snd_opti93x_interrupt, IRQF_DISABLED, DEV_NAME" - WSS", codec)) { | ||
1302 | snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq); | ||
1303 | snd_opti93x_free(codec); | ||
1304 | return -EBUSY; | ||
1305 | } | ||
1306 | |||
1307 | codec->card = card; | ||
1308 | codec->port = chip->wss_base + 4; | ||
1309 | codec->irq = chip->irq; | ||
1310 | |||
1311 | spin_lock_init(&codec->lock); | ||
1312 | codec->hardware = chip->hardware; | ||
1313 | codec->chip = chip; | ||
1314 | |||
1315 | if ((error = snd_opti93x_probe(codec))) { | ||
1316 | snd_opti93x_free(codec); | ||
1317 | return error; | ||
1318 | } | ||
1319 | |||
1320 | snd_opti93x_init(codec); | ||
1321 | |||
1322 | /* Register device */ | ||
1323 | if ((error = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops)) < 0) { | ||
1324 | snd_opti93x_free(codec); | ||
1325 | return error; | ||
1326 | } | ||
1327 | |||
1328 | *rcodec = codec; | ||
1329 | return 0; | ||
1330 | } | ||
1331 | |||
1332 | static struct snd_pcm_ops snd_opti93x_playback_ops = { | ||
1333 | .open = snd_opti93x_playback_open, | ||
1334 | .close = snd_opti93x_playback_close, | ||
1335 | .ioctl = snd_pcm_lib_ioctl, | ||
1336 | .hw_params = snd_opti93x_hw_params, | ||
1337 | .hw_free = snd_opti93x_hw_free, | ||
1338 | .prepare = snd_opti93x_playback_prepare, | ||
1339 | .trigger = snd_opti93x_playback_trigger, | ||
1340 | .pointer = snd_opti93x_playback_pointer, | ||
1341 | }; | ||
1342 | |||
1343 | static struct snd_pcm_ops snd_opti93x_capture_ops = { | ||
1344 | .open = snd_opti93x_capture_open, | ||
1345 | .close = snd_opti93x_capture_close, | ||
1346 | .ioctl = snd_pcm_lib_ioctl, | ||
1347 | .hw_params = snd_opti93x_hw_params, | ||
1348 | .hw_free = snd_opti93x_hw_free, | ||
1349 | .prepare = snd_opti93x_capture_prepare, | ||
1350 | .trigger = snd_opti93x_capture_trigger, | ||
1351 | .pointer = snd_opti93x_capture_pointer, | ||
1352 | }; | ||
1353 | |||
1354 | static int snd_opti93x_pcm(struct snd_opti93x *codec, int device, struct snd_pcm **rpcm) | ||
1355 | { | ||
1356 | int error; | ||
1357 | struct snd_pcm *pcm; | ||
1358 | |||
1359 | if ((error = snd_pcm_new(codec->card, "OPTi 82C93X", device, 1, 1, &pcm)) < 0) | ||
1360 | return error; | ||
1361 | |||
1362 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_opti93x_playback_ops); | ||
1363 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_opti93x_capture_ops); | ||
1364 | |||
1365 | pcm->private_data = codec; | ||
1366 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; | ||
1367 | |||
1368 | strcpy(pcm->name, snd_opti93x_chip_id(codec)); | ||
1369 | |||
1370 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, | ||
1371 | snd_dma_isa_data(), | ||
1372 | 64*1024, codec->dma1 > 3 || codec->dma2 > 3 ? 128*1024 : 64*1024); | ||
1373 | |||
1374 | codec->pcm = pcm; | ||
1375 | if (rpcm) | ||
1376 | *rpcm = pcm; | ||
1377 | return 0; | ||
1378 | } | ||
1379 | |||
1380 | /* | ||
1381 | * MIXER part | ||
1382 | */ | ||
1383 | |||
1384 | static int snd_opti93x_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | ||
1385 | { | ||
1386 | static char *texts[4] = { | ||
1387 | "Line1", "Aux", "Mic", "Mix" | ||
1388 | }; | ||
1389 | |||
1390 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
1391 | uinfo->count = 2; | ||
1392 | uinfo->value.enumerated.items = 4; | ||
1393 | if (uinfo->value.enumerated.item > 3) | ||
1394 | uinfo->value.enumerated.item = 3; | ||
1395 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); | ||
1396 | return 0; | ||
1397 | } | ||
1398 | |||
1399 | static int snd_opti93x_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | ||
1400 | { | ||
1401 | struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol); | ||
1402 | unsigned long flags; | ||
1403 | |||
1404 | spin_lock_irqsave(&chip->lock, flags); | ||
1405 | ucontrol->value.enumerated.item[0] = (chip->image[OPTi93X_MIXOUT_LEFT] & OPTi93X_MIXOUT_MIXER) >> 6; | ||
1406 | ucontrol->value.enumerated.item[1] = (chip->image[OPTi93X_MIXOUT_RIGHT] & OPTi93X_MIXOUT_MIXER) >> 6; | ||
1407 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1408 | return 0; | ||
1409 | } | ||
1410 | |||
1411 | static int snd_opti93x_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | ||
1412 | { | ||
1413 | struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol); | ||
1414 | unsigned long flags; | ||
1415 | unsigned short left, right; | ||
1416 | int change; | ||
1417 | |||
1418 | if (ucontrol->value.enumerated.item[0] > 3 || | ||
1419 | ucontrol->value.enumerated.item[1] > 3) | ||
1420 | return -EINVAL; | ||
1421 | left = ucontrol->value.enumerated.item[0] << 6; | ||
1422 | right = ucontrol->value.enumerated.item[1] << 6; | ||
1423 | spin_lock_irqsave(&chip->lock, flags); | ||
1424 | left = (chip->image[OPTi93X_MIXOUT_LEFT] & ~OPTi93X_MIXOUT_MIXER) | left; | ||
1425 | right = (chip->image[OPTi93X_MIXOUT_RIGHT] & ~OPTi93X_MIXOUT_MIXER) | right; | ||
1426 | change = left != chip->image[OPTi93X_MIXOUT_LEFT] || | ||
1427 | right != chip->image[OPTi93X_MIXOUT_RIGHT]; | ||
1428 | snd_opti93x_out_image(chip, OPTi93X_MIXOUT_LEFT, left); | ||
1429 | snd_opti93x_out_image(chip, OPTi93X_MIXOUT_RIGHT, right); | ||
1430 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1431 | return change; | ||
1432 | } | ||
1433 | |||
1434 | #if 0 | ||
1435 | |||
1436 | #define OPTi93X_SINGLE(xname, xindex, reg, shift, mask, invert) \ | ||
1437 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | ||
1438 | .info = snd_opti93x_info_single, \ | ||
1439 | .get = snd_opti93x_get_single, .put = snd_opti93x_put_single, \ | ||
1440 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } | ||
1441 | |||
1442 | static int snd_opti93x_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | ||
1443 | { | ||
1444 | int mask = (kcontrol->private_value >> 16) & 0xff; | ||
1445 | |||
1446 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
1447 | uinfo->count = 1; | ||
1448 | uinfo->value.integer.min = 0; | ||
1449 | uinfo->value.integer.max = mask; | ||
1450 | return 0; | ||
1451 | } | ||
1452 | |||
1453 | static int snd_opti93x_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | ||
1454 | { | ||
1455 | struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol); | ||
1456 | unsigned long flags; | ||
1457 | int reg = kcontrol->private_value & 0xff; | ||
1458 | int shift = (kcontrol->private_value >> 8) & 0xff; | ||
1459 | int mask = (kcontrol->private_value >> 16) & 0xff; | ||
1460 | int invert = (kcontrol->private_value >> 24) & 0xff; | ||
1461 | |||
1462 | spin_lock_irqsave(&chip->lock, flags); | ||
1463 | ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask; | ||
1464 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1465 | if (invert) | ||
1466 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; | ||
1467 | return 0; | ||
1468 | } | ||
1469 | |||
1470 | static int snd_opti93x_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | ||
1471 | { | ||
1472 | struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol); | ||
1473 | unsigned long flags; | ||
1474 | int reg = kcontrol->private_value & 0xff; | ||
1475 | int shift = (kcontrol->private_value >> 8) & 0xff; | ||
1476 | int mask = (kcontrol->private_value >> 16) & 0xff; | ||
1477 | int invert = (kcontrol->private_value >> 24) & 0xff; | ||
1478 | int change; | ||
1479 | unsigned short val; | ||
1480 | |||
1481 | val = (ucontrol->value.integer.value[0] & mask); | ||
1482 | if (invert) | ||
1483 | val = mask - val; | ||
1484 | val <<= shift; | ||
1485 | spin_lock_irqsave(&chip->lock, flags); | ||
1486 | val = (chip->image[reg] & ~(mask << shift)) | val; | ||
1487 | change = val != chip->image[reg]; | ||
1488 | snd_opti93x_out(chip, reg, val); | ||
1489 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1490 | return change; | ||
1491 | } | ||
1492 | |||
1493 | #endif /* single */ | ||
1494 | |||
1495 | #define OPTi93X_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ | ||
1496 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | ||
1497 | .info = snd_opti93x_info_double, \ | ||
1498 | .get = snd_opti93x_get_double, .put = snd_opti93x_put_double, \ | ||
1499 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } | ||
1500 | |||
1501 | #define OPTi93X_DOUBLE_INVERT_INVERT(xctl) \ | ||
1502 | do { xctl.private_value ^= 22; } while (0) | ||
1503 | #define OPTi93X_DOUBLE_CHANGE_REGS(xctl, left_reg, right_reg) \ | ||
1504 | do { xctl.private_value &= ~0x0000ffff; \ | ||
1505 | xctl.private_value |= left_reg | (right_reg << 8); } while (0) | ||
1506 | |||
1507 | static int snd_opti93x_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | ||
1508 | { | ||
1509 | int mask = (kcontrol->private_value >> 24) & 0xff; | ||
1510 | |||
1511 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; | ||
1512 | uinfo->count = 2; | ||
1513 | uinfo->value.integer.min = 0; | ||
1514 | uinfo->value.integer.max = mask; | ||
1515 | return 0; | ||
1516 | } | ||
1517 | |||
1518 | static int snd_opti93x_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | ||
1519 | { | ||
1520 | struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol); | ||
1521 | unsigned long flags; | ||
1522 | int left_reg = kcontrol->private_value & 0xff; | ||
1523 | int right_reg = (kcontrol->private_value >> 8) & 0xff; | ||
1524 | int shift_left = (kcontrol->private_value >> 16) & 0x07; | ||
1525 | int shift_right = (kcontrol->private_value >> 19) & 0x07; | ||
1526 | int mask = (kcontrol->private_value >> 24) & 0xff; | ||
1527 | int invert = (kcontrol->private_value >> 22) & 1; | ||
1528 | |||
1529 | spin_lock_irqsave(&chip->lock, flags); | ||
1530 | ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask; | ||
1531 | ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask; | ||
1532 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1533 | if (invert) { | ||
1534 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; | ||
1535 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; | ||
1536 | } | ||
1537 | return 0; | ||
1538 | } | ||
1539 | |||
1540 | static int snd_opti93x_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | ||
1541 | { | ||
1542 | struct snd_opti93x *chip = snd_kcontrol_chip(kcontrol); | ||
1543 | unsigned long flags; | ||
1544 | int left_reg = kcontrol->private_value & 0xff; | ||
1545 | int right_reg = (kcontrol->private_value >> 8) & 0xff; | ||
1546 | int shift_left = (kcontrol->private_value >> 16) & 0x07; | ||
1547 | int shift_right = (kcontrol->private_value >> 19) & 0x07; | ||
1548 | int mask = (kcontrol->private_value >> 24) & 0xff; | ||
1549 | int invert = (kcontrol->private_value >> 22) & 1; | ||
1550 | int change; | ||
1551 | unsigned short val1, val2; | ||
1552 | |||
1553 | val1 = ucontrol->value.integer.value[0] & mask; | ||
1554 | val2 = ucontrol->value.integer.value[1] & mask; | ||
1555 | if (invert) { | ||
1556 | val1 = mask - val1; | ||
1557 | val2 = mask - val2; | ||
1558 | } | ||
1559 | val1 <<= shift_left; | ||
1560 | val2 <<= shift_right; | ||
1561 | spin_lock_irqsave(&chip->lock, flags); | ||
1562 | val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; | ||
1563 | val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2; | ||
1564 | change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg]; | ||
1565 | snd_opti93x_out_image(chip, left_reg, val1); | ||
1566 | snd_opti93x_out_image(chip, right_reg, val2); | ||
1567 | spin_unlock_irqrestore(&chip->lock, flags); | ||
1568 | return change; | ||
1569 | } | ||
1570 | |||
1571 | static struct snd_kcontrol_new snd_opti93x_controls[] __devinitdata = { | ||
1572 | OPTi93X_DOUBLE("Master Playback Switch", 0, OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1), | ||
1573 | OPTi93X_DOUBLE("Master Playback Volume", 0, OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1), | ||
1574 | OPTi93X_DOUBLE("PCM Playback Switch", 0, OPTi93X_DAC_LEFT, OPTi93X_DAC_RIGHT, 7, 7, 1, 1), | ||
1575 | OPTi93X_DOUBLE("PCM Playback Volume", 0, OPTi93X_DAC_LEFT, OPTi93X_DAC_RIGHT, 0, 0, 31, 1), | ||
1576 | OPTi93X_DOUBLE("FM Playback Switch", 0, OPTi931_FM_LEFT_INPUT, OPTi931_FM_RIGHT_INPUT, 7, 7, 1, 1), | ||
1577 | OPTi93X_DOUBLE("FM Playback Volume", 0, OPTi931_FM_LEFT_INPUT, OPTi931_FM_RIGHT_INPUT, 1, 1, 15, 1), | ||
1578 | OPTi93X_DOUBLE("Line Playback Switch", 0, OPTi93X_LINE_LEFT_INPUT, OPTi93X_LINE_RIGHT_INPUT, 7, 7, 1, 1), | ||
1579 | OPTi93X_DOUBLE("Line Playback Volume", 0, OPTi93X_LINE_LEFT_INPUT, OPTi93X_LINE_RIGHT_INPUT, 1, 1, 15, 1), | ||
1580 | OPTi93X_DOUBLE("Mic Playback Switch", 0, OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1), | ||
1581 | OPTi93X_DOUBLE("Mic Playback Volume", 0, OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1), | ||
1582 | OPTi93X_DOUBLE("Mic Boost", 0, OPTi93X_MIXOUT_LEFT, OPTi93X_MIXOUT_RIGHT, 5, 5, 1, 1), | ||
1583 | OPTi93X_DOUBLE("CD Playback Switch", 0, OPTi93X_CD_LEFT_INPUT, OPTi93X_CD_RIGHT_INPUT, 7, 7, 1, 1), | ||
1584 | OPTi93X_DOUBLE("CD Playback Volume", 0, OPTi93X_CD_LEFT_INPUT, OPTi93X_CD_RIGHT_INPUT, 1, 1, 15, 1), | ||
1585 | OPTi93X_DOUBLE("Aux Playback Switch", 0, OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1), | ||
1586 | OPTi93X_DOUBLE("Aux Playback Volume", 0, OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1), | ||
1587 | OPTi93X_DOUBLE("Capture Volume", 0, OPTi93X_MIXOUT_LEFT, OPTi93X_MIXOUT_RIGHT, 0, 0, 15, 0), | ||
1588 | { | ||
1589 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
1590 | .name = "Capture Source", | ||
1591 | .info = snd_opti93x_info_mux, | ||
1592 | .get = snd_opti93x_get_mux, | ||
1593 | .put = snd_opti93x_put_mux, | ||
1594 | } | ||
1595 | }; | ||
1596 | |||
1597 | static int __devinit snd_opti93x_mixer(struct snd_opti93x *chip) | ||
1598 | { | ||
1599 | struct snd_card *card; | ||
1600 | struct snd_kcontrol_new knew; | ||
1601 | int err; | ||
1602 | unsigned int idx; | ||
1603 | |||
1604 | snd_assert(chip != NULL && chip->card != NULL, return -EINVAL); | ||
1605 | |||
1606 | card = chip->card; | ||
1607 | |||
1608 | strcpy(card->mixername, snd_opti93x_chip_id(chip)); | ||
1609 | |||
1610 | for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) { | ||
1611 | knew = snd_opti93x_controls[idx]; | ||
1612 | if (chip->hardware == OPTi9XX_HW_82C930) { | ||
1613 | if (strstr(knew.name, "FM")) /* skip FM controls */ | ||
1614 | continue; | ||
1615 | else if (strcmp(knew.name, "Mic Playback Volume")) | ||
1616 | OPTi93X_DOUBLE_INVERT_INVERT(knew); | ||
1617 | else if (strstr(knew.name, "Aux")) | ||
1618 | OPTi93X_DOUBLE_CHANGE_REGS(knew, OPTi930_AUX_LEFT_INPUT, OPTi930_AUX_RIGHT_INPUT); | ||
1619 | else if (strcmp(knew.name, "PCM Playback Volume")) | ||
1620 | OPTi93X_DOUBLE_INVERT_INVERT(knew); | ||
1621 | else if (strcmp(knew.name, "Master Playback Volume")) | ||
1622 | OPTi93X_DOUBLE_INVERT_INVERT(knew); | ||
1623 | } | ||
1624 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_opti93x_controls[idx], chip))) < 0) | ||
1625 | return err; | ||
1626 | } | ||
1627 | return 0; | ||
1628 | } | ||
1629 | |||
1630 | #endif /* OPTi93X */ | 576 | #endif /* OPTi93X */ |
1631 | 577 | ||
1632 | static int __devinit snd_card_opti9xx_detect(struct snd_card *card, | 578 | static int __devinit snd_card_opti9xx_detect(struct snd_card *card, |
@@ -1739,8 +685,16 @@ static void snd_card_opti9xx_free(struct snd_card *card) | |||
1739 | { | 685 | { |
1740 | struct snd_opti9xx *chip = card->private_data; | 686 | struct snd_opti9xx *chip = card->private_data; |
1741 | 687 | ||
1742 | if (chip) | 688 | if (chip) { |
689 | #ifdef OPTi93X | ||
690 | struct snd_cs4231 *codec = chip->codec; | ||
691 | if (codec->irq > 0) { | ||
692 | disable_irq(codec->irq); | ||
693 | free_irq(codec->irq, codec); | ||
694 | } | ||
695 | #endif | ||
1743 | release_and_free_resource(chip->res_mc_base); | 696 | release_and_free_resource(chip->res_mc_base); |
697 | } | ||
1744 | } | 698 | } |
1745 | 699 | ||
1746 | static int __devinit snd_opti9xx_probe(struct snd_card *card) | 700 | static int __devinit snd_opti9xx_probe(struct snd_card *card) |
@@ -1748,11 +702,11 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card) | |||
1748 | static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; | 702 | static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; |
1749 | int error; | 703 | int error; |
1750 | struct snd_opti9xx *chip = card->private_data; | 704 | struct snd_opti9xx *chip = card->private_data; |
1751 | #if defined(OPTi93X) | 705 | #if defined(CS4231) || defined(OPTi93X) |
1752 | struct snd_opti93x *codec; | ||
1753 | #elif defined(CS4231) | ||
1754 | struct snd_cs4231 *codec; | 706 | struct snd_cs4231 *codec; |
707 | #ifdef CS4231 | ||
1755 | struct snd_timer *timer; | 708 | struct snd_timer *timer; |
709 | #endif | ||
1756 | #else | 710 | #else |
1757 | struct snd_ad1848 *codec; | 711 | struct snd_ad1848 *codec; |
1758 | #endif | 712 | #endif |
@@ -1784,26 +738,34 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card) | |||
1784 | if ((error = snd_opti9xx_configure(chip))) | 738 | if ((error = snd_opti9xx_configure(chip))) |
1785 | return error; | 739 | return error; |
1786 | 740 | ||
1787 | #if defined(OPTi93X) | 741 | #if defined(CS4231) || defined(OPTi93X) |
1788 | if ((error = snd_opti93x_create(card, chip, chip->dma1, chip->dma2, &codec))) | ||
1789 | return error; | ||
1790 | if ((error = snd_opti93x_pcm(codec, 0, &pcm)) < 0) | ||
1791 | return error; | ||
1792 | if ((error = snd_opti93x_mixer(codec)) < 0) | ||
1793 | return error; | ||
1794 | #elif defined(CS4231) | ||
1795 | if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1, | 742 | if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1, |
1796 | chip->irq, chip->dma1, chip->dma2, | 743 | chip->irq, chip->dma1, chip->dma2, |
1797 | CS4231_HW_DETECT, | 744 | #ifdef CS4231 |
1798 | 0, | 745 | CS4231_HW_DETECT, 0, |
746 | #else /* OPTi93x */ | ||
747 | CS4231_HW_OPTI93X, CS4231_HWSHARE_IRQ, | ||
748 | #endif | ||
1799 | &codec)) < 0) | 749 | &codec)) < 0) |
1800 | return error; | 750 | return error; |
751 | #ifdef OPTi93X | ||
752 | chip->codec = codec; | ||
753 | #endif | ||
1801 | if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) | 754 | if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) |
1802 | return error; | 755 | return error; |
1803 | if ((error = snd_cs4231_mixer(codec)) < 0) | 756 | if ((error = snd_cs4231_mixer(codec)) < 0) |
1804 | return error; | 757 | return error; |
758 | #ifdef CS4231 | ||
1805 | if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) | 759 | if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) |
1806 | return error; | 760 | return error; |
761 | #else /* OPTI93X */ | ||
762 | error = request_irq(chip->irq, snd_opti93x_interrupt, | ||
763 | IRQF_DISABLED, DEV_NAME" - WSS", codec); | ||
764 | if (error < 0) { | ||
765 | snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq); | ||
766 | return error; | ||
767 | } | ||
768 | #endif | ||
1807 | #else | 769 | #else |
1808 | if ((error = snd_ad1848_create(card, chip->wss_base + 4, | 770 | if ((error = snd_ad1848_create(card, chip->wss_base + 4, |
1809 | chip->irq, chip->dma1, | 771 | chip->irq, chip->dma1, |