diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
commit | c71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch) | |
tree | ecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /sound/oss | |
parent | ea53c912f8a86a8567697115b6a0d8152beee5c8 (diff) | |
parent | 6a00f206debf8a5c8899055726ad127dbeeed098 (diff) |
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts:
litmus/sched_cedf.c
Diffstat (limited to 'sound/oss')
-rw-r--r-- | sound/oss/Kconfig | 12 | ||||
-rw-r--r-- | sound/oss/Makefile | 6 | ||||
-rw-r--r-- | sound/oss/ac97_codec.c | 1206 | ||||
-rw-r--r-- | sound/oss/au1550_ac97.c | 2147 | ||||
-rw-r--r-- | sound/oss/audio.c | 4 | ||||
-rw-r--r-- | sound/oss/dev_table.c | 6 | ||||
-rw-r--r-- | sound/oss/dev_table.h | 2 | ||||
-rw-r--r-- | sound/oss/dmasound/dmasound_core.c | 43 | ||||
-rw-r--r-- | sound/oss/midi_synth.c | 30 | ||||
-rw-r--r-- | sound/oss/midi_synth.h | 2 | ||||
-rw-r--r-- | sound/oss/midibuf.c | 6 | ||||
-rw-r--r-- | sound/oss/msnd_pinnacle.c | 16 | ||||
-rw-r--r-- | sound/oss/opl3.c | 23 | ||||
-rw-r--r-- | sound/oss/pss.c | 6 | ||||
-rw-r--r-- | sound/oss/sb_card.c | 2 | ||||
-rw-r--r-- | sound/oss/sb_ess.c | 3 | ||||
-rw-r--r-- | sound/oss/sequencer.c | 6 | ||||
-rw-r--r-- | sound/oss/sh_dac_audio.c | 325 | ||||
-rw-r--r-- | sound/oss/soundcard.c | 103 | ||||
-rw-r--r-- | sound/oss/swarm_cs4297a.c | 22 | ||||
-rw-r--r-- | sound/oss/vidc.c | 2 | ||||
-rw-r--r-- | sound/oss/vwsnd.c | 30 |
22 files changed, 149 insertions, 3853 deletions
diff --git a/sound/oss/Kconfig b/sound/oss/Kconfig index a513651fa149..6c93e051f9ae 100644 --- a/sound/oss/Kconfig +++ b/sound/oss/Kconfig | |||
@@ -22,10 +22,6 @@ config SOUND_VWSND | |||
22 | <file:Documentation/sound/oss/vwsnd> for more info on this driver's | 22 | <file:Documentation/sound/oss/vwsnd> for more info on this driver's |
23 | capabilities. | 23 | capabilities. |
24 | 24 | ||
25 | config SOUND_AU1550_AC97 | ||
26 | tristate "Au1550/Au1200 AC97 Sound" | ||
27 | depends on SOC_AU1550 || SOC_AU1200 | ||
28 | |||
29 | config SOUND_MSNDCLAS | 25 | config SOUND_MSNDCLAS |
30 | tristate "Support for Turtle Beach MultiSound Classic, Tahiti, Monterey" | 26 | tristate "Support for Turtle Beach MultiSound Classic, Tahiti, Monterey" |
31 | depends on (m || !STANDALONE) && ISA | 27 | depends on (m || !STANDALONE) && ISA |
@@ -545,11 +541,3 @@ config SOUND_KAHLUA | |||
545 | 541 | ||
546 | endif # SOUND_OSS | 542 | endif # SOUND_OSS |
547 | 543 | ||
548 | config SOUND_SH_DAC_AUDIO | ||
549 | tristate "SuperH DAC audio support" | ||
550 | depends on CPU_SH3 && HIGH_RES_TIMERS | ||
551 | |||
552 | config SOUND_SH_DAC_AUDIO_CHANNEL | ||
553 | int "DAC channel" | ||
554 | default "1" | ||
555 | depends on SOUND_SH_DAC_AUDIO | ||
diff --git a/sound/oss/Makefile b/sound/oss/Makefile index 567b8a74178a..77f21b68bf0f 100644 --- a/sound/oss/Makefile +++ b/sound/oss/Makefile | |||
@@ -9,7 +9,6 @@ obj-$(CONFIG_SOUND_OSS) += sound.o | |||
9 | 9 | ||
10 | # Please leave it as is, cause the link order is significant ! | 10 | # Please leave it as is, cause the link order is significant ! |
11 | 11 | ||
12 | obj-$(CONFIG_SOUND_SH_DAC_AUDIO) += sh_dac_audio.o | ||
13 | obj-$(CONFIG_SOUND_AEDSP16) += aedsp16.o | 12 | obj-$(CONFIG_SOUND_AEDSP16) += aedsp16.o |
14 | obj-$(CONFIG_SOUND_PSS) += pss.o ad1848.o mpu401.o | 13 | obj-$(CONFIG_SOUND_PSS) += pss.o ad1848.o mpu401.o |
15 | obj-$(CONFIG_SOUND_TRIX) += trix.o ad1848.o sb_lib.o uart401.o | 14 | obj-$(CONFIG_SOUND_TRIX) += trix.o ad1848.o sb_lib.o uart401.o |
@@ -26,7 +25,6 @@ obj-$(CONFIG_SOUND_WAVEARTIST) += waveartist.o | |||
26 | obj-$(CONFIG_SOUND_MSNDCLAS) += msnd.o msnd_classic.o | 25 | obj-$(CONFIG_SOUND_MSNDCLAS) += msnd.o msnd_classic.o |
27 | obj-$(CONFIG_SOUND_MSNDPIN) += msnd.o msnd_pinnacle.o | 26 | obj-$(CONFIG_SOUND_MSNDPIN) += msnd.o msnd_pinnacle.o |
28 | obj-$(CONFIG_SOUND_VWSND) += vwsnd.o | 27 | obj-$(CONFIG_SOUND_VWSND) += vwsnd.o |
29 | obj-$(CONFIG_SOUND_AU1550_AC97) += au1550_ac97.o ac97_codec.o | ||
30 | obj-$(CONFIG_SOUND_BCM_CS4297A) += swarm_cs4297a.o | 28 | obj-$(CONFIG_SOUND_BCM_CS4297A) += swarm_cs4297a.o |
31 | 29 | ||
32 | obj-$(CONFIG_DMASOUND) += dmasound/ | 30 | obj-$(CONFIG_DMASOUND) += dmasound/ |
@@ -88,7 +86,7 @@ ifeq ($(CONFIG_PSS_HAVE_BOOT),y) | |||
88 | $(obj)/bin2hex pss_synth < $< > $@ | 86 | $(obj)/bin2hex pss_synth < $< > $@ |
89 | else | 87 | else |
90 | $(obj)/pss_boot.h: | 88 | $(obj)/pss_boot.h: |
91 | ( \ | 89 | $(Q)( \ |
92 | echo 'static unsigned char * pss_synth = NULL;'; \ | 90 | echo 'static unsigned char * pss_synth = NULL;'; \ |
93 | echo 'static int pss_synthLen = 0;'; \ | 91 | echo 'static int pss_synthLen = 0;'; \ |
94 | ) > $@ | 92 | ) > $@ |
@@ -103,7 +101,7 @@ ifeq ($(CONFIG_TRIX_HAVE_BOOT),y) | |||
103 | $(obj)/hex2hex -i trix_boot < $< > $@ | 101 | $(obj)/hex2hex -i trix_boot < $< > $@ |
104 | else | 102 | else |
105 | $(obj)/trix_boot.h: | 103 | $(obj)/trix_boot.h: |
106 | ( \ | 104 | $(Q)( \ |
107 | echo 'static unsigned char * trix_boot = NULL;'; \ | 105 | echo 'static unsigned char * trix_boot = NULL;'; \ |
108 | echo 'static int trix_boot_len = 0;'; \ | 106 | echo 'static int trix_boot_len = 0;'; \ |
109 | ) > $@ | 107 | ) > $@ |
diff --git a/sound/oss/ac97_codec.c b/sound/oss/ac97_codec.c deleted file mode 100644 index 456a1b4d7832..000000000000 --- a/sound/oss/ac97_codec.c +++ /dev/null | |||
@@ -1,1206 +0,0 @@ | |||
1 | /* | ||
2 | * ac97_codec.c: Generic AC97 mixer/modem module | ||
3 | * | ||
4 | * Derived from ac97 mixer in maestro and trident driver. | ||
5 | * | ||
6 | * Copyright 2000 Silicon Integrated System Corporation | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | * | ||
22 | ************************************************************************** | ||
23 | * | ||
24 | * The Intel Audio Codec '97 specification is available at the Intel | ||
25 | * audio homepage: http://developer.intel.com/ial/scalableplatforms/audio/ | ||
26 | * | ||
27 | * The specification itself is currently available at: | ||
28 | * ftp://download.intel.com/ial/scalableplatforms/ac97r22.pdf | ||
29 | * | ||
30 | ************************************************************************** | ||
31 | * | ||
32 | * History | ||
33 | * May 02, 2003 Liam Girdwood <lrg@slimlogic.co.uk> | ||
34 | * Removed non existant WM9700 | ||
35 | * Added support for WM9705, WM9708, WM9709, WM9710, WM9711 | ||
36 | * WM9712 and WM9717 | ||
37 | * Mar 28, 2002 Randolph Bentson <bentson@holmsjoen.com> | ||
38 | * corrections to support WM9707 in ViewPad 1000 | ||
39 | * v0.4 Mar 15 2000 Ollie Lho | ||
40 | * dual codecs support verified with 4 channels output | ||
41 | * v0.3 Feb 22 2000 Ollie Lho | ||
42 | * bug fix for record mask setting | ||
43 | * v0.2 Feb 10 2000 Ollie Lho | ||
44 | * add ac97_read_proc for /proc/driver/{vendor}/ac97 | ||
45 | * v0.1 Jan 14 2000 Ollie Lho <ollie@sis.com.tw> | ||
46 | * Isolated from trident.c to support multiple ac97 codec | ||
47 | */ | ||
48 | #include <linux/module.h> | ||
49 | #include <linux/kernel.h> | ||
50 | #include <linux/slab.h> | ||
51 | #include <linux/string.h> | ||
52 | #include <linux/errno.h> | ||
53 | #include <linux/bitops.h> | ||
54 | #include <linux/delay.h> | ||
55 | #include <linux/pci.h> | ||
56 | #include <linux/ac97_codec.h> | ||
57 | #include <asm/uaccess.h> | ||
58 | #include <linux/mutex.h> | ||
59 | |||
60 | #define CODEC_ID_BUFSZ 14 | ||
61 | |||
62 | static int ac97_read_mixer(struct ac97_codec *codec, int oss_channel); | ||
63 | static void ac97_write_mixer(struct ac97_codec *codec, int oss_channel, | ||
64 | unsigned int left, unsigned int right); | ||
65 | static void ac97_set_mixer(struct ac97_codec *codec, unsigned int oss_mixer, unsigned int val ); | ||
66 | static int ac97_recmask_io(struct ac97_codec *codec, int rw, int mask); | ||
67 | static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned long arg); | ||
68 | |||
69 | static int ac97_init_mixer(struct ac97_codec *codec); | ||
70 | |||
71 | static int wolfson_init03(struct ac97_codec * codec); | ||
72 | static int wolfson_init04(struct ac97_codec * codec); | ||
73 | static int wolfson_init05(struct ac97_codec * codec); | ||
74 | static int wolfson_init11(struct ac97_codec * codec); | ||
75 | static int wolfson_init13(struct ac97_codec * codec); | ||
76 | static int tritech_init(struct ac97_codec * codec); | ||
77 | static int tritech_maestro_init(struct ac97_codec * codec); | ||
78 | static int sigmatel_9708_init(struct ac97_codec *codec); | ||
79 | static int sigmatel_9721_init(struct ac97_codec *codec); | ||
80 | static int sigmatel_9744_init(struct ac97_codec *codec); | ||
81 | static int ad1886_init(struct ac97_codec *codec); | ||
82 | static int eapd_control(struct ac97_codec *codec, int); | ||
83 | static int crystal_digital_control(struct ac97_codec *codec, int slots, int rate, int mode); | ||
84 | static int cmedia_init(struct ac97_codec * codec); | ||
85 | static int cmedia_digital_control(struct ac97_codec *codec, int slots, int rate, int mode); | ||
86 | static int generic_digital_control(struct ac97_codec *codec, int slots, int rate, int mode); | ||
87 | |||
88 | |||
89 | /* | ||
90 | * AC97 operations. | ||
91 | * | ||
92 | * If you are adding a codec then you should be able to use | ||
93 | * eapd_ops - any codec that supports EAPD amp control (most) | ||
94 | * null_ops - any ancient codec that supports nothing | ||
95 | * | ||
96 | * The three functions are | ||
97 | * init - used for non AC97 standard initialisation | ||
98 | * amplifier - used to do amplifier control (1=on 0=off) | ||
99 | * digital - switch to digital modes (0 = analog) | ||
100 | * | ||
101 | * Not all codecs support all features, not all drivers use all the | ||
102 | * operations yet | ||
103 | */ | ||
104 | |||
105 | static struct ac97_ops null_ops = { NULL, NULL, NULL }; | ||
106 | static struct ac97_ops default_ops = { NULL, eapd_control, NULL }; | ||
107 | static struct ac97_ops default_digital_ops = { NULL, eapd_control, generic_digital_control}; | ||
108 | static struct ac97_ops wolfson_ops03 = { wolfson_init03, NULL, NULL }; | ||
109 | static struct ac97_ops wolfson_ops04 = { wolfson_init04, NULL, NULL }; | ||
110 | static struct ac97_ops wolfson_ops05 = { wolfson_init05, NULL, NULL }; | ||
111 | static struct ac97_ops wolfson_ops11 = { wolfson_init11, NULL, NULL }; | ||
112 | static struct ac97_ops wolfson_ops13 = { wolfson_init13, NULL, NULL }; | ||
113 | static struct ac97_ops tritech_ops = { tritech_init, NULL, NULL }; | ||
114 | static struct ac97_ops tritech_m_ops = { tritech_maestro_init, NULL, NULL }; | ||
115 | static struct ac97_ops sigmatel_9708_ops = { sigmatel_9708_init, NULL, NULL }; | ||
116 | static struct ac97_ops sigmatel_9721_ops = { sigmatel_9721_init, NULL, NULL }; | ||
117 | static struct ac97_ops sigmatel_9744_ops = { sigmatel_9744_init, NULL, NULL }; | ||
118 | static struct ac97_ops crystal_digital_ops = { NULL, eapd_control, crystal_digital_control }; | ||
119 | static struct ac97_ops ad1886_ops = { ad1886_init, eapd_control, NULL }; | ||
120 | static struct ac97_ops cmedia_ops = { NULL, eapd_control, NULL}; | ||
121 | static struct ac97_ops cmedia_digital_ops = { cmedia_init, eapd_control, cmedia_digital_control}; | ||
122 | |||
123 | /* sorted by vendor/device id */ | ||
124 | static const struct { | ||
125 | u32 id; | ||
126 | char *name; | ||
127 | struct ac97_ops *ops; | ||
128 | int flags; | ||
129 | } ac97_codec_ids[] = { | ||
130 | {0x41445303, "Analog Devices AD1819", &null_ops}, | ||
131 | {0x41445340, "Analog Devices AD1881", &null_ops}, | ||
132 | {0x41445348, "Analog Devices AD1881A", &null_ops}, | ||
133 | {0x41445360, "Analog Devices AD1885", &default_ops}, | ||
134 | {0x41445361, "Analog Devices AD1886", &ad1886_ops}, | ||
135 | {0x41445370, "Analog Devices AD1981", &null_ops}, | ||
136 | {0x41445372, "Analog Devices AD1981A", &null_ops}, | ||
137 | {0x41445374, "Analog Devices AD1981B", &null_ops}, | ||
138 | {0x41445460, "Analog Devices AD1885", &default_ops}, | ||
139 | {0x41445461, "Analog Devices AD1886", &ad1886_ops}, | ||
140 | {0x414B4D00, "Asahi Kasei AK4540", &null_ops}, | ||
141 | {0x414B4D01, "Asahi Kasei AK4542", &null_ops}, | ||
142 | {0x414B4D02, "Asahi Kasei AK4543", &null_ops}, | ||
143 | {0x414C4326, "ALC100P", &null_ops}, | ||
144 | {0x414C4710, "ALC200/200P", &null_ops}, | ||
145 | {0x414C4720, "ALC650", &default_digital_ops}, | ||
146 | {0x434D4941, "CMedia", &cmedia_ops, AC97_NO_PCM_VOLUME }, | ||
147 | {0x434D4942, "CMedia", &cmedia_ops, AC97_NO_PCM_VOLUME }, | ||
148 | {0x434D4961, "CMedia", &cmedia_digital_ops, AC97_NO_PCM_VOLUME }, | ||
149 | {0x43525900, "Cirrus Logic CS4297", &default_ops}, | ||
150 | {0x43525903, "Cirrus Logic CS4297", &default_ops}, | ||
151 | {0x43525913, "Cirrus Logic CS4297A rev A", &default_ops}, | ||
152 | {0x43525914, "Cirrus Logic CS4297A rev B", &default_ops}, | ||
153 | {0x43525923, "Cirrus Logic CS4298", &null_ops}, | ||
154 | {0x4352592B, "Cirrus Logic CS4294", &null_ops}, | ||
155 | {0x4352592D, "Cirrus Logic CS4294", &null_ops}, | ||
156 | {0x43525931, "Cirrus Logic CS4299 rev A", &crystal_digital_ops}, | ||
157 | {0x43525933, "Cirrus Logic CS4299 rev C", &crystal_digital_ops}, | ||
158 | {0x43525934, "Cirrus Logic CS4299 rev D", &crystal_digital_ops}, | ||
159 | {0x43585430, "CXT48", &default_ops, AC97_DELUDED_MODEM }, | ||
160 | {0x43585442, "CXT66", &default_ops, AC97_DELUDED_MODEM }, | ||
161 | {0x44543031, "Diamond Technology DT0893", &default_ops}, | ||
162 | {0x45838308, "ESS Allegro ES1988", &null_ops}, | ||
163 | {0x49434511, "ICE1232", &null_ops}, /* I hope --jk */ | ||
164 | {0x4e534331, "National Semiconductor LM4549", &null_ops}, | ||
165 | {0x53494c22, "Silicon Laboratory Si3036", &null_ops}, | ||
166 | {0x53494c23, "Silicon Laboratory Si3038", &null_ops}, | ||
167 | {0x545200FF, "TriTech TR?????", &tritech_m_ops}, | ||
168 | {0x54524102, "TriTech TR28022", &null_ops}, | ||
169 | {0x54524103, "TriTech TR28023", &null_ops}, | ||
170 | {0x54524106, "TriTech TR28026", &null_ops}, | ||
171 | {0x54524108, "TriTech TR28028", &tritech_ops}, | ||
172 | {0x54524123, "TriTech TR A5", &null_ops}, | ||
173 | {0x574D4C03, "Wolfson WM9703/07/08/17", &wolfson_ops03}, | ||
174 | {0x574D4C04, "Wolfson WM9704M/WM9704Q", &wolfson_ops04}, | ||
175 | {0x574D4C05, "Wolfson WM9705/WM9710", &wolfson_ops05}, | ||
176 | {0x574D4C09, "Wolfson WM9709", &null_ops}, | ||
177 | {0x574D4C12, "Wolfson WM9711/9712", &wolfson_ops11}, | ||
178 | {0x574D4C13, "Wolfson WM9713", &wolfson_ops13, AC97_DEFAULT_POWER_OFF}, | ||
179 | {0x83847600, "SigmaTel STAC????", &null_ops}, | ||
180 | {0x83847604, "SigmaTel STAC9701/3/4/5", &null_ops}, | ||
181 | {0x83847605, "SigmaTel STAC9704", &null_ops}, | ||
182 | {0x83847608, "SigmaTel STAC9708", &sigmatel_9708_ops}, | ||
183 | {0x83847609, "SigmaTel STAC9721/23", &sigmatel_9721_ops}, | ||
184 | {0x83847644, "SigmaTel STAC9744/45", &sigmatel_9744_ops}, | ||
185 | {0x83847652, "SigmaTel STAC9752/53", &default_ops}, | ||
186 | {0x83847656, "SigmaTel STAC9756/57", &sigmatel_9744_ops}, | ||
187 | {0x83847666, "SigmaTel STAC9750T", &sigmatel_9744_ops}, | ||
188 | {0x83847684, "SigmaTel STAC9783/84?", &null_ops}, | ||
189 | {0x57454301, "Winbond 83971D", &null_ops}, | ||
190 | }; | ||
191 | |||
192 | /* this table has default mixer values for all OSS mixers. */ | ||
193 | static struct mixer_defaults { | ||
194 | int mixer; | ||
195 | unsigned int value; | ||
196 | } mixer_defaults[SOUND_MIXER_NRDEVICES] = { | ||
197 | /* all values 0 -> 100 in bytes */ | ||
198 | {SOUND_MIXER_VOLUME, 0x4343}, | ||
199 | {SOUND_MIXER_BASS, 0x4343}, | ||
200 | {SOUND_MIXER_TREBLE, 0x4343}, | ||
201 | {SOUND_MIXER_PCM, 0x4343}, | ||
202 | {SOUND_MIXER_SPEAKER, 0x4343}, | ||
203 | {SOUND_MIXER_LINE, 0x4343}, | ||
204 | {SOUND_MIXER_MIC, 0x0000}, | ||
205 | {SOUND_MIXER_CD, 0x4343}, | ||
206 | {SOUND_MIXER_ALTPCM, 0x4343}, | ||
207 | {SOUND_MIXER_IGAIN, 0x4343}, | ||
208 | {SOUND_MIXER_LINE1, 0x4343}, | ||
209 | {SOUND_MIXER_PHONEIN, 0x4343}, | ||
210 | {SOUND_MIXER_PHONEOUT, 0x4343}, | ||
211 | {SOUND_MIXER_VIDEO, 0x4343}, | ||
212 | {-1,0} | ||
213 | }; | ||
214 | |||
215 | /* table to scale scale from OSS mixer value to AC97 mixer register value */ | ||
216 | static struct ac97_mixer_hw { | ||
217 | unsigned char offset; | ||
218 | int scale; | ||
219 | } ac97_hw[SOUND_MIXER_NRDEVICES]= { | ||
220 | [SOUND_MIXER_VOLUME] = {AC97_MASTER_VOL_STEREO,64}, | ||
221 | [SOUND_MIXER_BASS] = {AC97_MASTER_TONE, 16}, | ||
222 | [SOUND_MIXER_TREBLE] = {AC97_MASTER_TONE, 16}, | ||
223 | [SOUND_MIXER_PCM] = {AC97_PCMOUT_VOL, 32}, | ||
224 | [SOUND_MIXER_SPEAKER] = {AC97_PCBEEP_VOL, 16}, | ||
225 | [SOUND_MIXER_LINE] = {AC97_LINEIN_VOL, 32}, | ||
226 | [SOUND_MIXER_MIC] = {AC97_MIC_VOL, 32}, | ||
227 | [SOUND_MIXER_CD] = {AC97_CD_VOL, 32}, | ||
228 | [SOUND_MIXER_ALTPCM] = {AC97_HEADPHONE_VOL, 64}, | ||
229 | [SOUND_MIXER_IGAIN] = {AC97_RECORD_GAIN, 16}, | ||
230 | [SOUND_MIXER_LINE1] = {AC97_AUX_VOL, 32}, | ||
231 | [SOUND_MIXER_PHONEIN] = {AC97_PHONE_VOL, 32}, | ||
232 | [SOUND_MIXER_PHONEOUT] = {AC97_MASTER_VOL_MONO, 64}, | ||
233 | [SOUND_MIXER_VIDEO] = {AC97_VIDEO_VOL, 32}, | ||
234 | }; | ||
235 | |||
236 | /* the following tables allow us to go from OSS <-> ac97 quickly. */ | ||
237 | enum ac97_recsettings { | ||
238 | AC97_REC_MIC=0, | ||
239 | AC97_REC_CD, | ||
240 | AC97_REC_VIDEO, | ||
241 | AC97_REC_AUX, | ||
242 | AC97_REC_LINE, | ||
243 | AC97_REC_STEREO, /* combination of all enabled outputs.. */ | ||
244 | AC97_REC_MONO, /*.. or the mono equivalent */ | ||
245 | AC97_REC_PHONE | ||
246 | }; | ||
247 | |||
248 | static const unsigned int ac97_rm2oss[] = { | ||
249 | [AC97_REC_MIC] = SOUND_MIXER_MIC, | ||
250 | [AC97_REC_CD] = SOUND_MIXER_CD, | ||
251 | [AC97_REC_VIDEO] = SOUND_MIXER_VIDEO, | ||
252 | [AC97_REC_AUX] = SOUND_MIXER_LINE1, | ||
253 | [AC97_REC_LINE] = SOUND_MIXER_LINE, | ||
254 | [AC97_REC_STEREO]= SOUND_MIXER_IGAIN, | ||
255 | [AC97_REC_PHONE] = SOUND_MIXER_PHONEIN | ||
256 | }; | ||
257 | |||
258 | /* indexed by bit position */ | ||
259 | static const unsigned int ac97_oss_rm[] = { | ||
260 | [SOUND_MIXER_MIC] = AC97_REC_MIC, | ||
261 | [SOUND_MIXER_CD] = AC97_REC_CD, | ||
262 | [SOUND_MIXER_VIDEO] = AC97_REC_VIDEO, | ||
263 | [SOUND_MIXER_LINE1] = AC97_REC_AUX, | ||
264 | [SOUND_MIXER_LINE] = AC97_REC_LINE, | ||
265 | [SOUND_MIXER_IGAIN] = AC97_REC_STEREO, | ||
266 | [SOUND_MIXER_PHONEIN] = AC97_REC_PHONE | ||
267 | }; | ||
268 | |||
269 | static LIST_HEAD(codecs); | ||
270 | static LIST_HEAD(codec_drivers); | ||
271 | static DEFINE_MUTEX(codec_mutex); | ||
272 | |||
273 | /* reads the given OSS mixer from the ac97 the caller must have insured that the ac97 knows | ||
274 | about that given mixer, and should be holding a spinlock for the card */ | ||
275 | static int ac97_read_mixer(struct ac97_codec *codec, int oss_channel) | ||
276 | { | ||
277 | u16 val; | ||
278 | int ret = 0; | ||
279 | int scale; | ||
280 | struct ac97_mixer_hw *mh = &ac97_hw[oss_channel]; | ||
281 | |||
282 | val = codec->codec_read(codec , mh->offset); | ||
283 | |||
284 | if (val & AC97_MUTE) { | ||
285 | ret = 0; | ||
286 | } else if (AC97_STEREO_MASK & (1 << oss_channel)) { | ||
287 | /* nice stereo mixers .. */ | ||
288 | int left,right; | ||
289 | |||
290 | left = (val >> 8) & 0x7f; | ||
291 | right = val & 0x7f; | ||
292 | |||
293 | if (oss_channel == SOUND_MIXER_IGAIN) { | ||
294 | right = (right * 100) / mh->scale; | ||
295 | left = (left * 100) / mh->scale; | ||
296 | } else { | ||
297 | /* these may have 5 or 6 bit resolution */ | ||
298 | if(oss_channel == SOUND_MIXER_VOLUME || oss_channel == SOUND_MIXER_ALTPCM) | ||
299 | scale = (1 << codec->bit_resolution); | ||
300 | else | ||
301 | scale = mh->scale; | ||
302 | |||
303 | right = 100 - ((right * 100) / scale); | ||
304 | left = 100 - ((left * 100) / scale); | ||
305 | } | ||
306 | ret = left | (right << 8); | ||
307 | } else if (oss_channel == SOUND_MIXER_SPEAKER) { | ||
308 | ret = 100 - ((((val & 0x1e)>>1) * 100) / mh->scale); | ||
309 | } else if (oss_channel == SOUND_MIXER_PHONEIN) { | ||
310 | ret = 100 - (((val & 0x1f) * 100) / mh->scale); | ||
311 | } else if (oss_channel == SOUND_MIXER_PHONEOUT) { | ||
312 | scale = (1 << codec->bit_resolution); | ||
313 | ret = 100 - (((val & 0x1f) * 100) / scale); | ||
314 | } else if (oss_channel == SOUND_MIXER_MIC) { | ||
315 | ret = 100 - (((val & 0x1f) * 100) / mh->scale); | ||
316 | /* the low bit is optional in the tone sliders and masking | ||
317 | it lets us avoid the 0xf 'bypass'.. */ | ||
318 | } else if (oss_channel == SOUND_MIXER_BASS) { | ||
319 | ret = 100 - ((((val >> 8) & 0xe) * 100) / mh->scale); | ||
320 | } else if (oss_channel == SOUND_MIXER_TREBLE) { | ||
321 | ret = 100 - (((val & 0xe) * 100) / mh->scale); | ||
322 | } | ||
323 | |||
324 | #ifdef DEBUG | ||
325 | printk("ac97_codec: read OSS mixer %2d (%s ac97 register 0x%02x), " | ||
326 | "0x%04x -> 0x%04x\n", | ||
327 | oss_channel, codec->id ? "Secondary" : "Primary", | ||
328 | mh->offset, val, ret); | ||
329 | #endif | ||
330 | |||
331 | return ret; | ||
332 | } | ||
333 | |||
334 | /* write the OSS encoded volume to the given OSS encoded mixer, again caller's job to | ||
335 | make sure all is well in arg land, call with spinlock held */ | ||
336 | static void ac97_write_mixer(struct ac97_codec *codec, int oss_channel, | ||
337 | unsigned int left, unsigned int right) | ||
338 | { | ||
339 | u16 val = 0; | ||
340 | int scale; | ||
341 | struct ac97_mixer_hw *mh = &ac97_hw[oss_channel]; | ||
342 | |||
343 | #ifdef DEBUG | ||
344 | printk("ac97_codec: wrote OSS mixer %2d (%s ac97 register 0x%02x), " | ||
345 | "left vol:%2d, right vol:%2d:", | ||
346 | oss_channel, codec->id ? "Secondary" : "Primary", | ||
347 | mh->offset, left, right); | ||
348 | #endif | ||
349 | |||
350 | if (AC97_STEREO_MASK & (1 << oss_channel)) { | ||
351 | /* stereo mixers */ | ||
352 | if (left == 0 && right == 0) { | ||
353 | val = AC97_MUTE; | ||
354 | } else { | ||
355 | if (oss_channel == SOUND_MIXER_IGAIN) { | ||
356 | right = (right * mh->scale) / 100; | ||
357 | left = (left * mh->scale) / 100; | ||
358 | if (right >= mh->scale) | ||
359 | right = mh->scale-1; | ||
360 | if (left >= mh->scale) | ||
361 | left = mh->scale-1; | ||
362 | } else { | ||
363 | /* these may have 5 or 6 bit resolution */ | ||
364 | if (oss_channel == SOUND_MIXER_VOLUME || | ||
365 | oss_channel == SOUND_MIXER_ALTPCM) | ||
366 | scale = (1 << codec->bit_resolution); | ||
367 | else | ||
368 | scale = mh->scale; | ||
369 | |||
370 | right = ((100 - right) * scale) / 100; | ||
371 | left = ((100 - left) * scale) / 100; | ||
372 | if (right >= scale) | ||
373 | right = scale-1; | ||
374 | if (left >= scale) | ||
375 | left = scale-1; | ||
376 | } | ||
377 | val = (left << 8) | right; | ||
378 | } | ||
379 | } else if (oss_channel == SOUND_MIXER_BASS) { | ||
380 | val = codec->codec_read(codec , mh->offset) & ~0x0f00; | ||
381 | left = ((100 - left) * mh->scale) / 100; | ||
382 | if (left >= mh->scale) | ||
383 | left = mh->scale-1; | ||
384 | val |= (left << 8) & 0x0e00; | ||
385 | } else if (oss_channel == SOUND_MIXER_TREBLE) { | ||
386 | val = codec->codec_read(codec , mh->offset) & ~0x000f; | ||
387 | left = ((100 - left) * mh->scale) / 100; | ||
388 | if (left >= mh->scale) | ||
389 | left = mh->scale-1; | ||
390 | val |= left & 0x000e; | ||
391 | } else if(left == 0) { | ||
392 | val = AC97_MUTE; | ||
393 | } else if (oss_channel == SOUND_MIXER_SPEAKER) { | ||
394 | left = ((100 - left) * mh->scale) / 100; | ||
395 | if (left >= mh->scale) | ||
396 | left = mh->scale-1; | ||
397 | val = left << 1; | ||
398 | } else if (oss_channel == SOUND_MIXER_PHONEIN) { | ||
399 | left = ((100 - left) * mh->scale) / 100; | ||
400 | if (left >= mh->scale) | ||
401 | left = mh->scale-1; | ||
402 | val = left; | ||
403 | } else if (oss_channel == SOUND_MIXER_PHONEOUT) { | ||
404 | scale = (1 << codec->bit_resolution); | ||
405 | left = ((100 - left) * scale) / 100; | ||
406 | if (left >= mh->scale) | ||
407 | left = mh->scale-1; | ||
408 | val = left; | ||
409 | } else if (oss_channel == SOUND_MIXER_MIC) { | ||
410 | val = codec->codec_read(codec , mh->offset) & ~0x801f; | ||
411 | left = ((100 - left) * mh->scale) / 100; | ||
412 | if (left >= mh->scale) | ||
413 | left = mh->scale-1; | ||
414 | val |= left; | ||
415 | /* the low bit is optional in the tone sliders and masking | ||
416 | it lets us avoid the 0xf 'bypass'.. */ | ||
417 | } | ||
418 | #ifdef DEBUG | ||
419 | printk(" 0x%04x", val); | ||
420 | #endif | ||
421 | |||
422 | codec->codec_write(codec, mh->offset, val); | ||
423 | |||
424 | #ifdef DEBUG | ||
425 | val = codec->codec_read(codec, mh->offset); | ||
426 | printk(" -> 0x%04x\n", val); | ||
427 | #endif | ||
428 | } | ||
429 | |||
430 | /* a thin wrapper for write_mixer */ | ||
431 | static void ac97_set_mixer(struct ac97_codec *codec, unsigned int oss_mixer, unsigned int val ) | ||
432 | { | ||
433 | unsigned int left,right; | ||
434 | |||
435 | /* cleanse input a little */ | ||
436 | right = ((val >> 8) & 0xff) ; | ||
437 | left = (val & 0xff) ; | ||
438 | |||
439 | if (right > 100) right = 100; | ||
440 | if (left > 100) left = 100; | ||
441 | |||
442 | codec->mixer_state[oss_mixer] = (right << 8) | left; | ||
443 | codec->write_mixer(codec, oss_mixer, left, right); | ||
444 | } | ||
445 | |||
446 | /* read or write the recmask, the ac97 can really have left and right recording | ||
447 | inputs independantly set, but OSS doesn't seem to want us to express that to | ||
448 | the user. the caller guarantees that we have a supported bit set, and they | ||
449 | must be holding the card's spinlock */ | ||
450 | static int ac97_recmask_io(struct ac97_codec *codec, int rw, int mask) | ||
451 | { | ||
452 | unsigned int val; | ||
453 | |||
454 | if (rw) { | ||
455 | /* read it from the card */ | ||
456 | val = codec->codec_read(codec, AC97_RECORD_SELECT); | ||
457 | #ifdef DEBUG | ||
458 | printk("ac97_codec: ac97 recmask to set to 0x%04x\n", val); | ||
459 | #endif | ||
460 | return (1 << ac97_rm2oss[val & 0x07]); | ||
461 | } | ||
462 | |||
463 | /* else, write the first set in the mask as the | ||
464 | output */ | ||
465 | /* clear out current set value first (AC97 supports only 1 input!) */ | ||
466 | val = (1 << ac97_rm2oss[codec->codec_read(codec, AC97_RECORD_SELECT) & 0x07]); | ||
467 | if (mask != val) | ||
468 | mask &= ~val; | ||
469 | |||
470 | val = ffs(mask); | ||
471 | val = ac97_oss_rm[val-1]; | ||
472 | val |= val << 8; /* set both channels */ | ||
473 | |||
474 | #ifdef DEBUG | ||
475 | printk("ac97_codec: setting ac97 recmask to 0x%04x\n", val); | ||
476 | #endif | ||
477 | |||
478 | codec->codec_write(codec, AC97_RECORD_SELECT, val); | ||
479 | |||
480 | return 0; | ||
481 | }; | ||
482 | |||
483 | static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned long arg) | ||
484 | { | ||
485 | int i, val = 0; | ||
486 | |||
487 | if (cmd == SOUND_MIXER_INFO) { | ||
488 | mixer_info info; | ||
489 | memset(&info, 0, sizeof(info)); | ||
490 | strlcpy(info.id, codec->name, sizeof(info.id)); | ||
491 | strlcpy(info.name, codec->name, sizeof(info.name)); | ||
492 | info.modify_counter = codec->modcnt; | ||
493 | if (copy_to_user((void __user *)arg, &info, sizeof(info))) | ||
494 | return -EFAULT; | ||
495 | return 0; | ||
496 | } | ||
497 | if (cmd == SOUND_OLD_MIXER_INFO) { | ||
498 | _old_mixer_info info; | ||
499 | memset(&info, 0, sizeof(info)); | ||
500 | strlcpy(info.id, codec->name, sizeof(info.id)); | ||
501 | strlcpy(info.name, codec->name, sizeof(info.name)); | ||
502 | if (copy_to_user((void __user *)arg, &info, sizeof(info))) | ||
503 | return -EFAULT; | ||
504 | return 0; | ||
505 | } | ||
506 | |||
507 | if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int)) | ||
508 | return -EINVAL; | ||
509 | |||
510 | if (cmd == OSS_GETVERSION) | ||
511 | return put_user(SOUND_VERSION, (int __user *)arg); | ||
512 | |||
513 | if (_SIOC_DIR(cmd) == _SIOC_READ) { | ||
514 | switch (_IOC_NR(cmd)) { | ||
515 | case SOUND_MIXER_RECSRC: /* give them the current record source */ | ||
516 | if (!codec->recmask_io) { | ||
517 | val = 0; | ||
518 | } else { | ||
519 | val = codec->recmask_io(codec, 1, 0); | ||
520 | } | ||
521 | break; | ||
522 | |||
523 | case SOUND_MIXER_DEVMASK: /* give them the supported mixers */ | ||
524 | val = codec->supported_mixers; | ||
525 | break; | ||
526 | |||
527 | case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */ | ||
528 | val = codec->record_sources; | ||
529 | break; | ||
530 | |||
531 | case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */ | ||
532 | val = codec->stereo_mixers; | ||
533 | break; | ||
534 | |||
535 | case SOUND_MIXER_CAPS: | ||
536 | val = SOUND_CAP_EXCL_INPUT; | ||
537 | break; | ||
538 | |||
539 | default: /* read a specific mixer */ | ||
540 | i = _IOC_NR(cmd); | ||
541 | |||
542 | if (!supported_mixer(codec, i)) | ||
543 | return -EINVAL; | ||
544 | |||
545 | /* do we ever want to touch the hardware? */ | ||
546 | /* val = codec->read_mixer(codec, i); */ | ||
547 | val = codec->mixer_state[i]; | ||
548 | break; | ||
549 | } | ||
550 | return put_user(val, (int __user *)arg); | ||
551 | } | ||
552 | |||
553 | if (_SIOC_DIR(cmd) == (_SIOC_WRITE|_SIOC_READ)) { | ||
554 | codec->modcnt++; | ||
555 | if (get_user(val, (int __user *)arg)) | ||
556 | return -EFAULT; | ||
557 | |||
558 | switch (_IOC_NR(cmd)) { | ||
559 | case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */ | ||
560 | if (!codec->recmask_io) return -EINVAL; | ||
561 | if (!val) return 0; | ||
562 | if (!(val &= codec->record_sources)) return -EINVAL; | ||
563 | |||
564 | codec->recmask_io(codec, 0, val); | ||
565 | |||
566 | return 0; | ||
567 | default: /* write a specific mixer */ | ||
568 | i = _IOC_NR(cmd); | ||
569 | |||
570 | if (!supported_mixer(codec, i)) | ||
571 | return -EINVAL; | ||
572 | |||
573 | ac97_set_mixer(codec, i, val); | ||
574 | |||
575 | return 0; | ||
576 | } | ||
577 | } | ||
578 | return -EINVAL; | ||
579 | } | ||
580 | |||
581 | /** | ||
582 | * codec_id - Turn id1/id2 into a PnP string | ||
583 | * @id1: Vendor ID1 | ||
584 | * @id2: Vendor ID2 | ||
585 | * @buf: CODEC_ID_BUFSZ byte buffer | ||
586 | * | ||
587 | * Fills buf with a zero terminated PnP ident string for the id1/id2 | ||
588 | * pair. For convenience the return is the passed in buffer pointer. | ||
589 | */ | ||
590 | |||
591 | static char *codec_id(u16 id1, u16 id2, char *buf) | ||
592 | { | ||
593 | if(id1&0x8080) { | ||
594 | snprintf(buf, CODEC_ID_BUFSZ, "0x%04x:0x%04x", id1, id2); | ||
595 | } else { | ||
596 | buf[0] = (id1 >> 8); | ||
597 | buf[1] = (id1 & 0xFF); | ||
598 | buf[2] = (id2 >> 8); | ||
599 | snprintf(buf+3, CODEC_ID_BUFSZ - 3, "%d", id2&0xFF); | ||
600 | } | ||
601 | return buf; | ||
602 | } | ||
603 | |||
604 | /** | ||
605 | * ac97_check_modem - Check if the Codec is a modem | ||
606 | * @codec: codec to check | ||
607 | * | ||
608 | * Return true if the device is an AC97 1.0 or AC97 2.0 modem | ||
609 | */ | ||
610 | |||
611 | static int ac97_check_modem(struct ac97_codec *codec) | ||
612 | { | ||
613 | /* Check for an AC97 1.0 soft modem (ID1) */ | ||
614 | if(codec->codec_read(codec, AC97_RESET) & 2) | ||
615 | return 1; | ||
616 | /* Check for an AC97 2.x soft modem */ | ||
617 | codec->codec_write(codec, AC97_EXTENDED_MODEM_ID, 0L); | ||
618 | if(codec->codec_read(codec, AC97_EXTENDED_MODEM_ID) & 1) | ||
619 | return 1; | ||
620 | return 0; | ||
621 | } | ||
622 | |||
623 | |||
624 | /** | ||
625 | * ac97_alloc_codec - Allocate an AC97 codec | ||
626 | * | ||
627 | * Returns a new AC97 codec structure. AC97 codecs may become | ||
628 | * refcounted soon so this interface is needed. Returns with | ||
629 | * one reference taken. | ||
630 | */ | ||
631 | |||
632 | struct ac97_codec *ac97_alloc_codec(void) | ||
633 | { | ||
634 | struct ac97_codec *codec = kzalloc(sizeof(struct ac97_codec), GFP_KERNEL); | ||
635 | if(!codec) | ||
636 | return NULL; | ||
637 | |||
638 | spin_lock_init(&codec->lock); | ||
639 | INIT_LIST_HEAD(&codec->list); | ||
640 | return codec; | ||
641 | } | ||
642 | |||
643 | EXPORT_SYMBOL(ac97_alloc_codec); | ||
644 | |||
645 | /** | ||
646 | * ac97_release_codec - Release an AC97 codec | ||
647 | * @codec: codec to release | ||
648 | * | ||
649 | * Release an allocated AC97 codec. This will be refcounted in | ||
650 | * time but for the moment is trivial. Calls the unregister | ||
651 | * handler if the codec is now defunct. | ||
652 | */ | ||
653 | |||
654 | void ac97_release_codec(struct ac97_codec *codec) | ||
655 | { | ||
656 | /* Remove from the list first, we don't want to be | ||
657 | "rediscovered" */ | ||
658 | mutex_lock(&codec_mutex); | ||
659 | list_del(&codec->list); | ||
660 | mutex_unlock(&codec_mutex); | ||
661 | /* | ||
662 | * The driver needs to deal with internal | ||
663 | * locking to avoid accidents here. | ||
664 | */ | ||
665 | if(codec->driver) | ||
666 | codec->driver->remove(codec, codec->driver); | ||
667 | kfree(codec); | ||
668 | } | ||
669 | |||
670 | EXPORT_SYMBOL(ac97_release_codec); | ||
671 | |||
672 | /** | ||
673 | * ac97_probe_codec - Initialize and setup AC97-compatible codec | ||
674 | * @codec: (in/out) Kernel info for a single AC97 codec | ||
675 | * | ||
676 | * Reset the AC97 codec, then initialize the mixer and | ||
677 | * the rest of the @codec structure. | ||
678 | * | ||
679 | * The codec_read and codec_write fields of @codec are | ||
680 | * required to be setup and working when this function | ||
681 | * is called. All other fields are set by this function. | ||
682 | * | ||
683 | * codec_wait field of @codec can optionally be provided | ||
684 | * when calling this function. If codec_wait is not %NULL, | ||
685 | * this function will call codec_wait any time it is | ||
686 | * necessary to wait for the audio chip to reach the | ||
687 | * codec-ready state. If codec_wait is %NULL, then | ||
688 | * the default behavior is to call schedule_timeout. | ||
689 | * Currently codec_wait is used to wait for AC97 codec | ||
690 | * reset to complete. | ||
691 | * | ||
692 | * Some codecs will power down when a register reset is | ||
693 | * performed. We now check for such codecs. | ||
694 | * | ||
695 | * Returns 1 (true) on success, or 0 (false) on failure. | ||
696 | */ | ||
697 | |||
698 | int ac97_probe_codec(struct ac97_codec *codec) | ||
699 | { | ||
700 | u16 id1, id2; | ||
701 | u16 audio; | ||
702 | int i; | ||
703 | char cidbuf[CODEC_ID_BUFSZ]; | ||
704 | u16 f; | ||
705 | struct list_head *l; | ||
706 | struct ac97_driver *d; | ||
707 | |||
708 | /* wait for codec-ready state */ | ||
709 | if (codec->codec_wait) | ||
710 | codec->codec_wait(codec); | ||
711 | else | ||
712 | udelay(10); | ||
713 | |||
714 | /* will the codec power down if register reset ? */ | ||
715 | id1 = codec->codec_read(codec, AC97_VENDOR_ID1); | ||
716 | id2 = codec->codec_read(codec, AC97_VENDOR_ID2); | ||
717 | codec->name = NULL; | ||
718 | codec->codec_ops = &null_ops; | ||
719 | for (i = 0; i < ARRAY_SIZE(ac97_codec_ids); i++) { | ||
720 | if (ac97_codec_ids[i].id == ((id1 << 16) | id2)) { | ||
721 | codec->type = ac97_codec_ids[i].id; | ||
722 | codec->name = ac97_codec_ids[i].name; | ||
723 | codec->codec_ops = ac97_codec_ids[i].ops; | ||
724 | codec->flags = ac97_codec_ids[i].flags; | ||
725 | break; | ||
726 | } | ||
727 | } | ||
728 | |||
729 | codec->model = (id1 << 16) | id2; | ||
730 | if ((codec->flags & AC97_DEFAULT_POWER_OFF) == 0) { | ||
731 | /* reset codec and wait for the ready bit before we continue */ | ||
732 | codec->codec_write(codec, AC97_RESET, 0L); | ||
733 | if (codec->codec_wait) | ||
734 | codec->codec_wait(codec); | ||
735 | else | ||
736 | udelay(10); | ||
737 | } | ||
738 | |||
739 | /* probing AC97 codec, AC97 2.0 says that bit 15 of register 0x00 (reset) should | ||
740 | * be read zero. | ||
741 | * | ||
742 | * FIXME: is the following comment outdated? -jgarzik | ||
743 | * Probing of AC97 in this way is not reliable, it is not even SAFE !! | ||
744 | */ | ||
745 | if ((audio = codec->codec_read(codec, AC97_RESET)) & 0x8000) { | ||
746 | printk(KERN_ERR "ac97_codec: %s ac97 codec not present\n", | ||
747 | (codec->id & 0x2) ? (codec->id&1 ? "4th" : "Tertiary") | ||
748 | : (codec->id&1 ? "Secondary": "Primary")); | ||
749 | return 0; | ||
750 | } | ||
751 | |||
752 | /* probe for Modem Codec */ | ||
753 | codec->modem = ac97_check_modem(codec); | ||
754 | |||
755 | /* enable SPDIF */ | ||
756 | f = codec->codec_read(codec, AC97_EXTENDED_STATUS); | ||
757 | if((codec->codec_ops == &null_ops) && (f & 4)) | ||
758 | codec->codec_ops = &default_digital_ops; | ||
759 | |||
760 | /* A device which thinks its a modem but isnt */ | ||
761 | if(codec->flags & AC97_DELUDED_MODEM) | ||
762 | codec->modem = 0; | ||
763 | |||
764 | if (codec->name == NULL) | ||
765 | codec->name = "Unknown"; | ||
766 | printk(KERN_INFO "ac97_codec: AC97 %s codec, id: %s (%s)\n", | ||
767 | codec->modem ? "Modem" : (audio ? "Audio" : ""), | ||
768 | codec_id(id1, id2, cidbuf), codec->name); | ||
769 | |||
770 | if(!ac97_init_mixer(codec)) | ||
771 | return 0; | ||
772 | |||
773 | /* | ||
774 | * Attach last so the caller can override the mixer | ||
775 | * callbacks. | ||
776 | */ | ||
777 | |||
778 | mutex_lock(&codec_mutex); | ||
779 | list_add(&codec->list, &codecs); | ||
780 | |||
781 | list_for_each(l, &codec_drivers) { | ||
782 | d = list_entry(l, struct ac97_driver, list); | ||
783 | if ((codec->model ^ d->codec_id) & d->codec_mask) | ||
784 | continue; | ||
785 | if(d->probe(codec, d) == 0) | ||
786 | { | ||
787 | codec->driver = d; | ||
788 | break; | ||
789 | } | ||
790 | } | ||
791 | |||
792 | mutex_unlock(&codec_mutex); | ||
793 | return 1; | ||
794 | } | ||
795 | |||
796 | static int ac97_init_mixer(struct ac97_codec *codec) | ||
797 | { | ||
798 | u16 cap; | ||
799 | int i; | ||
800 | |||
801 | cap = codec->codec_read(codec, AC97_RESET); | ||
802 | |||
803 | /* mixer masks */ | ||
804 | codec->supported_mixers = AC97_SUPPORTED_MASK; | ||
805 | codec->stereo_mixers = AC97_STEREO_MASK; | ||
806 | codec->record_sources = AC97_RECORD_MASK; | ||
807 | if (!(cap & 0x04)) | ||
808 | codec->supported_mixers &= ~(SOUND_MASK_BASS|SOUND_MASK_TREBLE); | ||
809 | if (!(cap & 0x10)) | ||
810 | codec->supported_mixers &= ~SOUND_MASK_ALTPCM; | ||
811 | |||
812 | |||
813 | /* detect bit resolution */ | ||
814 | codec->codec_write(codec, AC97_MASTER_VOL_STEREO, 0x2020); | ||
815 | if(codec->codec_read(codec, AC97_MASTER_VOL_STEREO) == 0x2020) | ||
816 | codec->bit_resolution = 6; | ||
817 | else | ||
818 | codec->bit_resolution = 5; | ||
819 | |||
820 | /* generic OSS to AC97 wrapper */ | ||
821 | codec->read_mixer = ac97_read_mixer; | ||
822 | codec->write_mixer = ac97_write_mixer; | ||
823 | codec->recmask_io = ac97_recmask_io; | ||
824 | codec->mixer_ioctl = ac97_mixer_ioctl; | ||
825 | |||
826 | /* initialize mixer channel volumes */ | ||
827 | for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { | ||
828 | struct mixer_defaults *md = &mixer_defaults[i]; | ||
829 | if (md->mixer == -1) | ||
830 | break; | ||
831 | if (!supported_mixer(codec, md->mixer)) | ||
832 | continue; | ||
833 | ac97_set_mixer(codec, md->mixer, md->value); | ||
834 | } | ||
835 | |||
836 | /* codec specific initialization for 4-6 channel output or secondary codec stuff */ | ||
837 | if (codec->codec_ops->init != NULL) { | ||
838 | codec->codec_ops->init(codec); | ||
839 | } | ||
840 | |||
841 | /* | ||
842 | * Volume is MUTE only on this device. We have to initialise | ||
843 | * it but its useless beyond that. | ||
844 | */ | ||
845 | if(codec->flags & AC97_NO_PCM_VOLUME) | ||
846 | { | ||
847 | codec->supported_mixers &= ~SOUND_MASK_PCM; | ||
848 | printk(KERN_WARNING "AC97 codec does not have proper volume support.\n"); | ||
849 | } | ||
850 | return 1; | ||
851 | } | ||
852 | |||
853 | #define AC97_SIGMATEL_ANALOG 0x6c /* Analog Special */ | ||
854 | #define AC97_SIGMATEL_DAC2INVERT 0x6e | ||
855 | #define AC97_SIGMATEL_BIAS1 0x70 | ||
856 | #define AC97_SIGMATEL_BIAS2 0x72 | ||
857 | #define AC97_SIGMATEL_MULTICHN 0x74 /* Multi-Channel programming */ | ||
858 | #define AC97_SIGMATEL_CIC1 0x76 | ||
859 | #define AC97_SIGMATEL_CIC2 0x78 | ||
860 | |||
861 | |||
862 | static int sigmatel_9708_init(struct ac97_codec * codec) | ||
863 | { | ||
864 | u16 codec72, codec6c; | ||
865 | |||
866 | codec72 = codec->codec_read(codec, AC97_SIGMATEL_BIAS2) & 0x8000; | ||
867 | codec6c = codec->codec_read(codec, AC97_SIGMATEL_ANALOG); | ||
868 | |||
869 | if ((codec72==0) && (codec6c==0)) { | ||
870 | codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba); | ||
871 | codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x1000); | ||
872 | codec->codec_write(codec, AC97_SIGMATEL_BIAS1, 0xabba); | ||
873 | codec->codec_write(codec, AC97_SIGMATEL_BIAS2, 0x0007); | ||
874 | } else if ((codec72==0x8000) && (codec6c==0)) { | ||
875 | codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba); | ||
876 | codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x1001); | ||
877 | codec->codec_write(codec, AC97_SIGMATEL_DAC2INVERT, 0x0008); | ||
878 | } else if ((codec72==0x8000) && (codec6c==0x0080)) { | ||
879 | /* nothing */ | ||
880 | } | ||
881 | codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x0000); | ||
882 | return 0; | ||
883 | } | ||
884 | |||
885 | |||
886 | static int sigmatel_9721_init(struct ac97_codec * codec) | ||
887 | { | ||
888 | /* Only set up secondary codec */ | ||
889 | if (codec->id == 0) | ||
890 | return 0; | ||
891 | |||
892 | codec->codec_write(codec, AC97_SURROUND_MASTER, 0L); | ||
893 | |||
894 | /* initialize SigmaTel STAC9721/23 as secondary codec, decoding AC link | ||
895 | sloc 3,4 = 0x01, slot 7,8 = 0x00, */ | ||
896 | codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x00); | ||
897 | |||
898 | /* we don't have the crystal when we are on an AMR card, so use | ||
899 | BIT_CLK as our clock source. Write the magic word ABBA and read | ||
900 | back to enable register 0x78 */ | ||
901 | codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba); | ||
902 | codec->codec_read(codec, AC97_SIGMATEL_CIC1); | ||
903 | |||
904 | /* sync all the clocks*/ | ||
905 | codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x3802); | ||
906 | |||
907 | return 0; | ||
908 | } | ||
909 | |||
910 | |||
911 | static int sigmatel_9744_init(struct ac97_codec * codec) | ||
912 | { | ||
913 | // patch for SigmaTel | ||
914 | codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba); | ||
915 | codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x0000); // is this correct? --jk | ||
916 | codec->codec_write(codec, AC97_SIGMATEL_BIAS1, 0xabba); | ||
917 | codec->codec_write(codec, AC97_SIGMATEL_BIAS2, 0x0002); | ||
918 | codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x0000); | ||
919 | return 0; | ||
920 | } | ||
921 | |||
922 | static int cmedia_init(struct ac97_codec *codec) | ||
923 | { | ||
924 | /* Initialise the CMedia 9739 */ | ||
925 | /* | ||
926 | We could set various options here | ||
927 | Register 0x20 bit 0x100 sets mic as center bass | ||
928 | Also do multi_channel_ctrl &=~0x3000 |=0x1000 | ||
929 | |||
930 | For now we set up the GPIO and PC beep | ||
931 | */ | ||
932 | |||
933 | u16 v; | ||
934 | |||
935 | /* MIC */ | ||
936 | codec->codec_write(codec, 0x64, 0x3000); | ||
937 | v = codec->codec_read(codec, 0x64); | ||
938 | v &= ~0x8000; | ||
939 | codec->codec_write(codec, 0x64, v); | ||
940 | codec->codec_write(codec, 0x70, 0x0100); | ||
941 | codec->codec_write(codec, 0x72, 0x0020); | ||
942 | return 0; | ||
943 | } | ||
944 | |||
945 | #define AC97_WM97XX_FMIXER_VOL 0x72 | ||
946 | #define AC97_WM97XX_RMIXER_VOL 0x74 | ||
947 | #define AC97_WM97XX_TEST 0x5a | ||
948 | #define AC97_WM9704_RPCM_VOL 0x70 | ||
949 | #define AC97_WM9711_OUT3VOL 0x16 | ||
950 | |||
951 | static int wolfson_init03(struct ac97_codec * codec) | ||
952 | { | ||
953 | /* this is known to work for the ViewSonic ViewPad 1000 */ | ||
954 | codec->codec_write(codec, AC97_WM97XX_FMIXER_VOL, 0x0808); | ||
955 | codec->codec_write(codec, AC97_GENERAL_PURPOSE, 0x8000); | ||
956 | return 0; | ||
957 | } | ||
958 | |||
959 | static int wolfson_init04(struct ac97_codec * codec) | ||
960 | { | ||
961 | codec->codec_write(codec, AC97_WM97XX_FMIXER_VOL, 0x0808); | ||
962 | codec->codec_write(codec, AC97_WM97XX_RMIXER_VOL, 0x0808); | ||
963 | |||
964 | // patch for DVD noise | ||
965 | codec->codec_write(codec, AC97_WM97XX_TEST, 0x0200); | ||
966 | |||
967 | // init vol as PCM vol | ||
968 | codec->codec_write(codec, AC97_WM9704_RPCM_VOL, | ||
969 | codec->codec_read(codec, AC97_PCMOUT_VOL)); | ||
970 | |||
971 | /* set rear surround volume */ | ||
972 | codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0000); | ||
973 | return 0; | ||
974 | } | ||
975 | |||
976 | /* WM9705, WM9710 */ | ||
977 | static int wolfson_init05(struct ac97_codec * codec) | ||
978 | { | ||
979 | /* set front mixer volume */ | ||
980 | codec->codec_write(codec, AC97_WM97XX_FMIXER_VOL, 0x0808); | ||
981 | return 0; | ||
982 | } | ||
983 | |||
984 | /* WM9711, WM9712 */ | ||
985 | static int wolfson_init11(struct ac97_codec * codec) | ||
986 | { | ||
987 | /* stop pop's during suspend/resume */ | ||
988 | codec->codec_write(codec, AC97_WM97XX_TEST, | ||
989 | codec->codec_read(codec, AC97_WM97XX_TEST) & 0xffbf); | ||
990 | |||
991 | /* set out3 volume */ | ||
992 | codec->codec_write(codec, AC97_WM9711_OUT3VOL, 0x0808); | ||
993 | return 0; | ||
994 | } | ||
995 | |||
996 | /* WM9713 */ | ||
997 | static int wolfson_init13(struct ac97_codec * codec) | ||
998 | { | ||
999 | codec->codec_write(codec, AC97_RECORD_GAIN, 0x00a0); | ||
1000 | codec->codec_write(codec, AC97_POWER_CONTROL, 0x0000); | ||
1001 | codec->codec_write(codec, AC97_EXTENDED_MODEM_ID, 0xDA00); | ||
1002 | codec->codec_write(codec, AC97_EXTEND_MODEM_STAT, 0x3810); | ||
1003 | codec->codec_write(codec, AC97_PHONE_VOL, 0x0808); | ||
1004 | codec->codec_write(codec, AC97_PCBEEP_VOL, 0x0808); | ||
1005 | |||
1006 | return 0; | ||
1007 | } | ||
1008 | |||
1009 | static int tritech_init(struct ac97_codec * codec) | ||
1010 | { | ||
1011 | codec->codec_write(codec, 0x26, 0x0300); | ||
1012 | codec->codec_write(codec, 0x26, 0x0000); | ||
1013 | codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0000); | ||
1014 | codec->codec_write(codec, AC97_RESERVED_3A, 0x0000); | ||
1015 | return 0; | ||
1016 | } | ||
1017 | |||
1018 | |||
1019 | /* copied from drivers/sound/maestro.c */ | ||
1020 | static int tritech_maestro_init(struct ac97_codec * codec) | ||
1021 | { | ||
1022 | /* no idea what this does */ | ||
1023 | codec->codec_write(codec, 0x2A, 0x0001); | ||
1024 | codec->codec_write(codec, 0x2C, 0x0000); | ||
1025 | codec->codec_write(codec, 0x2C, 0XFFFF); | ||
1026 | return 0; | ||
1027 | } | ||
1028 | |||
1029 | |||
1030 | |||
1031 | /* | ||
1032 | * Presario700 workaround | ||
1033 | * for Jack Sense/SPDIF Register mis-setting causing | ||
1034 | * no audible output | ||
1035 | * by Santiago Nullo 04/05/2002 | ||
1036 | */ | ||
1037 | |||
1038 | #define AC97_AD1886_JACK_SENSE 0x72 | ||
1039 | |||
1040 | static int ad1886_init(struct ac97_codec * codec) | ||
1041 | { | ||
1042 | /* from AD1886 Specs */ | ||
1043 | codec->codec_write(codec, AC97_AD1886_JACK_SENSE, 0x0010); | ||
1044 | return 0; | ||
1045 | } | ||
1046 | |||
1047 | |||
1048 | |||
1049 | |||
1050 | /* | ||
1051 | * This is basically standard AC97. It should work as a default for | ||
1052 | * almost all modern codecs. Note that some cards wire EAPD *backwards* | ||
1053 | * That side of it is up to the card driver not us to cope with. | ||
1054 | * | ||
1055 | */ | ||
1056 | |||
1057 | static int eapd_control(struct ac97_codec * codec, int on) | ||
1058 | { | ||
1059 | if(on) | ||
1060 | codec->codec_write(codec, AC97_POWER_CONTROL, | ||
1061 | codec->codec_read(codec, AC97_POWER_CONTROL)|0x8000); | ||
1062 | else | ||
1063 | codec->codec_write(codec, AC97_POWER_CONTROL, | ||
1064 | codec->codec_read(codec, AC97_POWER_CONTROL)&~0x8000); | ||
1065 | return 0; | ||
1066 | } | ||
1067 | |||
1068 | static int generic_digital_control(struct ac97_codec *codec, int slots, int rate, int mode) | ||
1069 | { | ||
1070 | u16 reg; | ||
1071 | |||
1072 | reg = codec->codec_read(codec, AC97_SPDIF_CONTROL); | ||
1073 | |||
1074 | switch(rate) | ||
1075 | { | ||
1076 | /* Off by default */ | ||
1077 | default: | ||
1078 | case 0: | ||
1079 | reg = codec->codec_read(codec, AC97_EXTENDED_STATUS); | ||
1080 | codec->codec_write(codec, AC97_EXTENDED_STATUS, (reg & ~AC97_EA_SPDIF)); | ||
1081 | if(rate == 0) | ||
1082 | return 0; | ||
1083 | return -EINVAL; | ||
1084 | case 1: | ||
1085 | reg = (reg & AC97_SC_SPSR_MASK) | AC97_SC_SPSR_48K; | ||
1086 | break; | ||
1087 | case 2: | ||
1088 | reg = (reg & AC97_SC_SPSR_MASK) | AC97_SC_SPSR_44K; | ||
1089 | break; | ||
1090 | case 3: | ||
1091 | reg = (reg & AC97_SC_SPSR_MASK) | AC97_SC_SPSR_32K; | ||
1092 | break; | ||
1093 | } | ||
1094 | |||
1095 | reg &= ~AC97_SC_CC_MASK; | ||
1096 | reg |= (mode & AUDIO_CCMASK) << 6; | ||
1097 | |||
1098 | if(mode & AUDIO_DIGITAL) | ||
1099 | reg |= 2; | ||
1100 | if(mode & AUDIO_PRO) | ||
1101 | reg |= 1; | ||
1102 | if(mode & AUDIO_DRS) | ||
1103 | reg |= 0x4000; | ||
1104 | |||
1105 | codec->codec_write(codec, AC97_SPDIF_CONTROL, reg); | ||
1106 | |||
1107 | reg = codec->codec_read(codec, AC97_EXTENDED_STATUS); | ||
1108 | reg &= (AC97_EA_SLOT_MASK); | ||
1109 | reg |= AC97_EA_VRA | AC97_EA_SPDIF | slots; | ||
1110 | codec->codec_write(codec, AC97_EXTENDED_STATUS, reg); | ||
1111 | |||
1112 | reg = codec->codec_read(codec, AC97_EXTENDED_STATUS); | ||
1113 | if(!(reg & 0x0400)) | ||
1114 | { | ||
1115 | codec->codec_write(codec, AC97_EXTENDED_STATUS, reg & ~ AC97_EA_SPDIF); | ||
1116 | return -EINVAL; | ||
1117 | } | ||
1118 | return 0; | ||
1119 | } | ||
1120 | |||
1121 | /* | ||
1122 | * Crystal digital audio control (CS4299) | ||
1123 | */ | ||
1124 | |||
1125 | static int crystal_digital_control(struct ac97_codec *codec, int slots, int rate, int mode) | ||
1126 | { | ||
1127 | u16 cv; | ||
1128 | |||
1129 | if(mode & AUDIO_DIGITAL) | ||
1130 | return -EINVAL; | ||
1131 | |||
1132 | switch(rate) | ||
1133 | { | ||
1134 | case 0: cv = 0x0; break; /* SPEN off */ | ||
1135 | case 48000: cv = 0x8004; break; /* 48KHz digital */ | ||
1136 | case 44100: cv = 0x8104; break; /* 44.1KHz digital */ | ||
1137 | case 32768: /* 32Khz */ | ||
1138 | default: | ||
1139 | return -EINVAL; | ||
1140 | } | ||
1141 | codec->codec_write(codec, 0x68, cv); | ||
1142 | return 0; | ||
1143 | } | ||
1144 | |||
1145 | /* | ||
1146 | * CMedia digital audio control | ||
1147 | * Needs more work. | ||
1148 | */ | ||
1149 | |||
1150 | static int cmedia_digital_control(struct ac97_codec *codec, int slots, int rate, int mode) | ||
1151 | { | ||
1152 | u16 cv; | ||
1153 | |||
1154 | if(mode & AUDIO_DIGITAL) | ||
1155 | return -EINVAL; | ||
1156 | |||
1157 | switch(rate) | ||
1158 | { | ||
1159 | case 0: cv = 0x0001; break; /* SPEN off */ | ||
1160 | case 48000: cv = 0x0009; break; /* 48KHz digital */ | ||
1161 | default: | ||
1162 | return -EINVAL; | ||
1163 | } | ||
1164 | codec->codec_write(codec, 0x2A, 0x05c4); | ||
1165 | codec->codec_write(codec, 0x6C, cv); | ||
1166 | |||
1167 | /* Switch on mix to surround */ | ||
1168 | cv = codec->codec_read(codec, 0x64); | ||
1169 | cv &= ~0x0200; | ||
1170 | if(mode) | ||
1171 | cv |= 0x0200; | ||
1172 | codec->codec_write(codec, 0x64, cv); | ||
1173 | return 0; | ||
1174 | } | ||
1175 | |||
1176 | |||
1177 | /* copied from drivers/sound/maestro.c */ | ||
1178 | #if 0 /* there has been 1 person on the planet with a pt101 that we | ||
1179 | know of. If they care, they can put this back in :) */ | ||
1180 | static int pt101_init(struct ac97_codec * codec) | ||
1181 | { | ||
1182 | printk(KERN_INFO "ac97_codec: PT101 Codec detected, initializing but _not_ installing mixer device.\n"); | ||
1183 | /* who knows.. */ | ||
1184 | codec->codec_write(codec, 0x2A, 0x0001); | ||
1185 | codec->codec_write(codec, 0x2C, 0x0000); | ||
1186 | codec->codec_write(codec, 0x2C, 0xFFFF); | ||
1187 | codec->codec_write(codec, 0x10, 0x9F1F); | ||
1188 | codec->codec_write(codec, 0x12, 0x0808); | ||
1189 | codec->codec_write(codec, 0x14, 0x9F1F); | ||
1190 | codec->codec_write(codec, 0x16, 0x9F1F); | ||
1191 | codec->codec_write(codec, 0x18, 0x0404); | ||
1192 | codec->codec_write(codec, 0x1A, 0x0000); | ||
1193 | codec->codec_write(codec, 0x1C, 0x0000); | ||
1194 | codec->codec_write(codec, 0x02, 0x0404); | ||
1195 | codec->codec_write(codec, 0x04, 0x0808); | ||
1196 | codec->codec_write(codec, 0x0C, 0x801F); | ||
1197 | codec->codec_write(codec, 0x0E, 0x801F); | ||
1198 | return 0; | ||
1199 | } | ||
1200 | #endif | ||
1201 | |||
1202 | |||
1203 | EXPORT_SYMBOL(ac97_probe_codec); | ||
1204 | |||
1205 | MODULE_LICENSE("GPL"); | ||
1206 | |||
diff --git a/sound/oss/au1550_ac97.c b/sound/oss/au1550_ac97.c deleted file mode 100644 index c6f2621221ba..000000000000 --- a/sound/oss/au1550_ac97.c +++ /dev/null | |||
@@ -1,2147 +0,0 @@ | |||
1 | /* | ||
2 | * au1550_ac97.c -- Sound driver for Alchemy Au1550 MIPS Internet Edge | ||
3 | * Processor. | ||
4 | * | ||
5 | * Copyright 2004 Embedded Edge, LLC | ||
6 | * dan@embeddededge.com | ||
7 | * | ||
8 | * Mostly copied from the au1000.c driver and some from the | ||
9 | * PowerMac dbdma driver. | ||
10 | * We assume the processor can do memory coherent DMA. | ||
11 | * | ||
12 | * Ported to 2.6 by Matt Porter <mporter@kernel.crashing.org> | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify it | ||
15 | * under the terms of the GNU General Public License as published by the | ||
16 | * Free Software Foundation; either version 2 of the License, or (at your | ||
17 | * option) any later version. | ||
18 | * | ||
19 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | ||
20 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | ||
22 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
25 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | * | ||
30 | * You should have received a copy of the GNU General Public License along | ||
31 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
32 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
33 | * | ||
34 | */ | ||
35 | |||
36 | #undef DEBUG | ||
37 | |||
38 | #include <linux/module.h> | ||
39 | #include <linux/string.h> | ||
40 | #include <linux/ioport.h> | ||
41 | #include <linux/sched.h> | ||
42 | #include <linux/delay.h> | ||
43 | #include <linux/sound.h> | ||
44 | #include <linux/slab.h> | ||
45 | #include <linux/soundcard.h> | ||
46 | #include <linux/smp_lock.h> | ||
47 | #include <linux/init.h> | ||
48 | #include <linux/interrupt.h> | ||
49 | #include <linux/kernel.h> | ||
50 | #include <linux/poll.h> | ||
51 | #include <linux/bitops.h> | ||
52 | #include <linux/spinlock.h> | ||
53 | #include <linux/ac97_codec.h> | ||
54 | #include <linux/mutex.h> | ||
55 | |||
56 | #include <asm/io.h> | ||
57 | #include <asm/uaccess.h> | ||
58 | #include <asm/hardirq.h> | ||
59 | #include <asm/mach-au1x00/au1xxx_psc.h> | ||
60 | #include <asm/mach-au1x00/au1xxx_dbdma.h> | ||
61 | #include <asm/mach-au1x00/au1xxx.h> | ||
62 | |||
63 | #undef OSS_DOCUMENTED_MIXER_SEMANTICS | ||
64 | |||
65 | /* misc stuff */ | ||
66 | #define POLL_COUNT 0x50000 | ||
67 | #define AC97_EXT_DACS (AC97_EXTID_SDAC | AC97_EXTID_CDAC | AC97_EXTID_LDAC) | ||
68 | |||
69 | /* The number of DBDMA ring descriptors to allocate. No sense making | ||
70 | * this too large....if you can't keep up with a few you aren't likely | ||
71 | * to be able to with lots of them, either. | ||
72 | */ | ||
73 | #define NUM_DBDMA_DESCRIPTORS 4 | ||
74 | |||
75 | #define err(format, arg...) printk(KERN_ERR format "\n" , ## arg) | ||
76 | |||
77 | /* Boot options | ||
78 | * 0 = no VRA, 1 = use VRA if codec supports it | ||
79 | */ | ||
80 | static int vra = 1; | ||
81 | module_param(vra, bool, 0); | ||
82 | MODULE_PARM_DESC(vra, "if 1 use VRA if codec supports it"); | ||
83 | |||
84 | static struct au1550_state { | ||
85 | /* soundcore stuff */ | ||
86 | int dev_audio; | ||
87 | |||
88 | struct ac97_codec *codec; | ||
89 | unsigned codec_base_caps; /* AC'97 reg 00h, "Reset Register" */ | ||
90 | unsigned codec_ext_caps; /* AC'97 reg 28h, "Extended Audio ID" */ | ||
91 | int no_vra; /* do not use VRA */ | ||
92 | |||
93 | spinlock_t lock; | ||
94 | struct mutex open_mutex; | ||
95 | struct mutex sem; | ||
96 | fmode_t open_mode; | ||
97 | wait_queue_head_t open_wait; | ||
98 | |||
99 | struct dmabuf { | ||
100 | u32 dmanr; | ||
101 | unsigned sample_rate; | ||
102 | unsigned src_factor; | ||
103 | unsigned sample_size; | ||
104 | int num_channels; | ||
105 | int dma_bytes_per_sample; | ||
106 | int user_bytes_per_sample; | ||
107 | int cnt_factor; | ||
108 | |||
109 | void *rawbuf; | ||
110 | unsigned buforder; | ||
111 | unsigned numfrag; | ||
112 | unsigned fragshift; | ||
113 | void *nextIn; | ||
114 | void *nextOut; | ||
115 | int count; | ||
116 | unsigned total_bytes; | ||
117 | unsigned error; | ||
118 | wait_queue_head_t wait; | ||
119 | |||
120 | /* redundant, but makes calculations easier */ | ||
121 | unsigned fragsize; | ||
122 | unsigned dma_fragsize; | ||
123 | unsigned dmasize; | ||
124 | unsigned dma_qcount; | ||
125 | |||
126 | /* OSS stuff */ | ||
127 | unsigned mapped:1; | ||
128 | unsigned ready:1; | ||
129 | unsigned stopped:1; | ||
130 | unsigned ossfragshift; | ||
131 | int ossmaxfrags; | ||
132 | unsigned subdivision; | ||
133 | } dma_dac, dma_adc; | ||
134 | } au1550_state; | ||
135 | |||
136 | static unsigned | ||
137 | ld2(unsigned int x) | ||
138 | { | ||
139 | unsigned r = 0; | ||
140 | |||
141 | if (x >= 0x10000) { | ||
142 | x >>= 16; | ||
143 | r += 16; | ||
144 | } | ||
145 | if (x >= 0x100) { | ||
146 | x >>= 8; | ||
147 | r += 8; | ||
148 | } | ||
149 | if (x >= 0x10) { | ||
150 | x >>= 4; | ||
151 | r += 4; | ||
152 | } | ||
153 | if (x >= 4) { | ||
154 | x >>= 2; | ||
155 | r += 2; | ||
156 | } | ||
157 | if (x >= 2) | ||
158 | r++; | ||
159 | return r; | ||
160 | } | ||
161 | |||
162 | static void | ||
163 | au1550_delay(int msec) | ||
164 | { | ||
165 | if (in_interrupt()) | ||
166 | return; | ||
167 | |||
168 | schedule_timeout_uninterruptible(msecs_to_jiffies(msec)); | ||
169 | } | ||
170 | |||
171 | static u16 | ||
172 | rdcodec(struct ac97_codec *codec, u8 addr) | ||
173 | { | ||
174 | struct au1550_state *s = (struct au1550_state *)codec->private_data; | ||
175 | unsigned long flags; | ||
176 | u32 cmd, val; | ||
177 | u16 data; | ||
178 | int i; | ||
179 | |||
180 | spin_lock_irqsave(&s->lock, flags); | ||
181 | |||
182 | for (i = 0; i < POLL_COUNT; i++) { | ||
183 | val = au_readl(PSC_AC97STAT); | ||
184 | au_sync(); | ||
185 | if (!(val & PSC_AC97STAT_CP)) | ||
186 | break; | ||
187 | } | ||
188 | if (i == POLL_COUNT) | ||
189 | err("rdcodec: codec cmd pending expired!"); | ||
190 | |||
191 | cmd = (u32)PSC_AC97CDC_INDX(addr); | ||
192 | cmd |= PSC_AC97CDC_RD; /* read command */ | ||
193 | au_writel(cmd, PSC_AC97CDC); | ||
194 | au_sync(); | ||
195 | |||
196 | /* now wait for the data | ||
197 | */ | ||
198 | for (i = 0; i < POLL_COUNT; i++) { | ||
199 | val = au_readl(PSC_AC97STAT); | ||
200 | au_sync(); | ||
201 | if (!(val & PSC_AC97STAT_CP)) | ||
202 | break; | ||
203 | } | ||
204 | if (i == POLL_COUNT) { | ||
205 | err("rdcodec: read poll expired!"); | ||
206 | data = 0; | ||
207 | goto out; | ||
208 | } | ||
209 | |||
210 | /* wait for command done? | ||
211 | */ | ||
212 | for (i = 0; i < POLL_COUNT; i++) { | ||
213 | val = au_readl(PSC_AC97EVNT); | ||
214 | au_sync(); | ||
215 | if (val & PSC_AC97EVNT_CD) | ||
216 | break; | ||
217 | } | ||
218 | if (i == POLL_COUNT) { | ||
219 | err("rdcodec: read cmdwait expired!"); | ||
220 | data = 0; | ||
221 | goto out; | ||
222 | } | ||
223 | |||
224 | data = au_readl(PSC_AC97CDC) & 0xffff; | ||
225 | au_sync(); | ||
226 | |||
227 | /* Clear command done event. | ||
228 | */ | ||
229 | au_writel(PSC_AC97EVNT_CD, PSC_AC97EVNT); | ||
230 | au_sync(); | ||
231 | |||
232 | out: | ||
233 | spin_unlock_irqrestore(&s->lock, flags); | ||
234 | |||
235 | return data; | ||
236 | } | ||
237 | |||
238 | |||
239 | static void | ||
240 | wrcodec(struct ac97_codec *codec, u8 addr, u16 data) | ||
241 | { | ||
242 | struct au1550_state *s = (struct au1550_state *)codec->private_data; | ||
243 | unsigned long flags; | ||
244 | u32 cmd, val; | ||
245 | int i; | ||
246 | |||
247 | spin_lock_irqsave(&s->lock, flags); | ||
248 | |||
249 | for (i = 0; i < POLL_COUNT; i++) { | ||
250 | val = au_readl(PSC_AC97STAT); | ||
251 | au_sync(); | ||
252 | if (!(val & PSC_AC97STAT_CP)) | ||
253 | break; | ||
254 | } | ||
255 | if (i == POLL_COUNT) | ||
256 | err("wrcodec: codec cmd pending expired!"); | ||
257 | |||
258 | cmd = (u32)PSC_AC97CDC_INDX(addr); | ||
259 | cmd |= (u32)data; | ||
260 | au_writel(cmd, PSC_AC97CDC); | ||
261 | au_sync(); | ||
262 | |||
263 | for (i = 0; i < POLL_COUNT; i++) { | ||
264 | val = au_readl(PSC_AC97STAT); | ||
265 | au_sync(); | ||
266 | if (!(val & PSC_AC97STAT_CP)) | ||
267 | break; | ||
268 | } | ||
269 | if (i == POLL_COUNT) | ||
270 | err("wrcodec: codec cmd pending expired!"); | ||
271 | |||
272 | for (i = 0; i < POLL_COUNT; i++) { | ||
273 | val = au_readl(PSC_AC97EVNT); | ||
274 | au_sync(); | ||
275 | if (val & PSC_AC97EVNT_CD) | ||
276 | break; | ||
277 | } | ||
278 | if (i == POLL_COUNT) | ||
279 | err("wrcodec: read cmdwait expired!"); | ||
280 | |||
281 | /* Clear command done event. | ||
282 | */ | ||
283 | au_writel(PSC_AC97EVNT_CD, PSC_AC97EVNT); | ||
284 | au_sync(); | ||
285 | |||
286 | spin_unlock_irqrestore(&s->lock, flags); | ||
287 | } | ||
288 | |||
289 | static void | ||
290 | waitcodec(struct ac97_codec *codec) | ||
291 | { | ||
292 | u16 temp; | ||
293 | u32 val; | ||
294 | int i; | ||
295 | |||
296 | /* codec_wait is used to wait for a ready state after | ||
297 | * an AC97C_RESET. | ||
298 | */ | ||
299 | au1550_delay(10); | ||
300 | |||
301 | /* first poll the CODEC_READY tag bit | ||
302 | */ | ||
303 | for (i = 0; i < POLL_COUNT; i++) { | ||
304 | val = au_readl(PSC_AC97STAT); | ||
305 | au_sync(); | ||
306 | if (val & PSC_AC97STAT_CR) | ||
307 | break; | ||
308 | } | ||
309 | if (i == POLL_COUNT) { | ||
310 | err("waitcodec: CODEC_READY poll expired!"); | ||
311 | return; | ||
312 | } | ||
313 | |||
314 | /* get AC'97 powerdown control/status register | ||
315 | */ | ||
316 | temp = rdcodec(codec, AC97_POWER_CONTROL); | ||
317 | |||
318 | /* If anything is powered down, power'em up | ||
319 | */ | ||
320 | if (temp & 0x7f00) { | ||
321 | /* Power on | ||
322 | */ | ||
323 | wrcodec(codec, AC97_POWER_CONTROL, 0); | ||
324 | au1550_delay(100); | ||
325 | |||
326 | /* Reread | ||
327 | */ | ||
328 | temp = rdcodec(codec, AC97_POWER_CONTROL); | ||
329 | } | ||
330 | |||
331 | /* Check if Codec REF,ANL,DAC,ADC ready | ||
332 | */ | ||
333 | if ((temp & 0x7f0f) != 0x000f) | ||
334 | err("codec reg 26 status (0x%x) not ready!!", temp); | ||
335 | } | ||
336 | |||
337 | /* stop the ADC before calling */ | ||
338 | static void | ||
339 | set_adc_rate(struct au1550_state *s, unsigned rate) | ||
340 | { | ||
341 | struct dmabuf *adc = &s->dma_adc; | ||
342 | struct dmabuf *dac = &s->dma_dac; | ||
343 | unsigned adc_rate, dac_rate; | ||
344 | u16 ac97_extstat; | ||
345 | |||
346 | if (s->no_vra) { | ||
347 | /* calc SRC factor | ||
348 | */ | ||
349 | adc->src_factor = ((96000 / rate) + 1) >> 1; | ||
350 | adc->sample_rate = 48000 / adc->src_factor; | ||
351 | return; | ||
352 | } | ||
353 | |||
354 | adc->src_factor = 1; | ||
355 | |||
356 | ac97_extstat = rdcodec(s->codec, AC97_EXTENDED_STATUS); | ||
357 | |||
358 | rate = rate > 48000 ? 48000 : rate; | ||
359 | |||
360 | /* enable VRA | ||
361 | */ | ||
362 | wrcodec(s->codec, AC97_EXTENDED_STATUS, | ||
363 | ac97_extstat | AC97_EXTSTAT_VRA); | ||
364 | |||
365 | /* now write the sample rate | ||
366 | */ | ||
367 | wrcodec(s->codec, AC97_PCM_LR_ADC_RATE, (u16) rate); | ||
368 | |||
369 | /* read it back for actual supported rate | ||
370 | */ | ||
371 | adc_rate = rdcodec(s->codec, AC97_PCM_LR_ADC_RATE); | ||
372 | |||
373 | pr_debug("set_adc_rate: set to %d Hz\n", adc_rate); | ||
374 | |||
375 | /* some codec's don't allow unequal DAC and ADC rates, in which case | ||
376 | * writing one rate reg actually changes both. | ||
377 | */ | ||
378 | dac_rate = rdcodec(s->codec, AC97_PCM_FRONT_DAC_RATE); | ||
379 | if (dac->num_channels > 2) | ||
380 | wrcodec(s->codec, AC97_PCM_SURR_DAC_RATE, dac_rate); | ||
381 | if (dac->num_channels > 4) | ||
382 | wrcodec(s->codec, AC97_PCM_LFE_DAC_RATE, dac_rate); | ||
383 | |||
384 | adc->sample_rate = adc_rate; | ||
385 | dac->sample_rate = dac_rate; | ||
386 | } | ||
387 | |||
388 | /* stop the DAC before calling */ | ||
389 | static void | ||
390 | set_dac_rate(struct au1550_state *s, unsigned rate) | ||
391 | { | ||
392 | struct dmabuf *dac = &s->dma_dac; | ||
393 | struct dmabuf *adc = &s->dma_adc; | ||
394 | unsigned adc_rate, dac_rate; | ||
395 | u16 ac97_extstat; | ||
396 | |||
397 | if (s->no_vra) { | ||
398 | /* calc SRC factor | ||
399 | */ | ||
400 | dac->src_factor = ((96000 / rate) + 1) >> 1; | ||
401 | dac->sample_rate = 48000 / dac->src_factor; | ||
402 | return; | ||
403 | } | ||
404 | |||
405 | dac->src_factor = 1; | ||
406 | |||
407 | ac97_extstat = rdcodec(s->codec, AC97_EXTENDED_STATUS); | ||
408 | |||
409 | rate = rate > 48000 ? 48000 : rate; | ||
410 | |||
411 | /* enable VRA | ||
412 | */ | ||
413 | wrcodec(s->codec, AC97_EXTENDED_STATUS, | ||
414 | ac97_extstat | AC97_EXTSTAT_VRA); | ||
415 | |||
416 | /* now write the sample rate | ||
417 | */ | ||
418 | wrcodec(s->codec, AC97_PCM_FRONT_DAC_RATE, (u16) rate); | ||
419 | |||
420 | /* I don't support different sample rates for multichannel, | ||
421 | * so make these channels the same. | ||
422 | */ | ||
423 | if (dac->num_channels > 2) | ||
424 | wrcodec(s->codec, AC97_PCM_SURR_DAC_RATE, (u16) rate); | ||
425 | if (dac->num_channels > 4) | ||
426 | wrcodec(s->codec, AC97_PCM_LFE_DAC_RATE, (u16) rate); | ||
427 | /* read it back for actual supported rate | ||
428 | */ | ||
429 | dac_rate = rdcodec(s->codec, AC97_PCM_FRONT_DAC_RATE); | ||
430 | |||
431 | pr_debug("set_dac_rate: set to %d Hz\n", dac_rate); | ||
432 | |||
433 | /* some codec's don't allow unequal DAC and ADC rates, in which case | ||
434 | * writing one rate reg actually changes both. | ||
435 | */ | ||
436 | adc_rate = rdcodec(s->codec, AC97_PCM_LR_ADC_RATE); | ||
437 | |||
438 | dac->sample_rate = dac_rate; | ||
439 | adc->sample_rate = adc_rate; | ||
440 | } | ||
441 | |||
442 | static void | ||
443 | stop_dac(struct au1550_state *s) | ||
444 | { | ||
445 | struct dmabuf *db = &s->dma_dac; | ||
446 | u32 stat; | ||
447 | unsigned long flags; | ||
448 | |||
449 | if (db->stopped) | ||
450 | return; | ||
451 | |||
452 | spin_lock_irqsave(&s->lock, flags); | ||
453 | |||
454 | au_writel(PSC_AC97PCR_TP, PSC_AC97PCR); | ||
455 | au_sync(); | ||
456 | |||
457 | /* Wait for Transmit Busy to show disabled. | ||
458 | */ | ||
459 | do { | ||
460 | stat = au_readl(PSC_AC97STAT); | ||
461 | au_sync(); | ||
462 | } while ((stat & PSC_AC97STAT_TB) != 0); | ||
463 | |||
464 | au1xxx_dbdma_reset(db->dmanr); | ||
465 | |||
466 | db->stopped = 1; | ||
467 | |||
468 | spin_unlock_irqrestore(&s->lock, flags); | ||
469 | } | ||
470 | |||
471 | static void | ||
472 | stop_adc(struct au1550_state *s) | ||
473 | { | ||
474 | struct dmabuf *db = &s->dma_adc; | ||
475 | unsigned long flags; | ||
476 | u32 stat; | ||
477 | |||
478 | if (db->stopped) | ||
479 | return; | ||
480 | |||
481 | spin_lock_irqsave(&s->lock, flags); | ||
482 | |||
483 | au_writel(PSC_AC97PCR_RP, PSC_AC97PCR); | ||
484 | au_sync(); | ||
485 | |||
486 | /* Wait for Receive Busy to show disabled. | ||
487 | */ | ||
488 | do { | ||
489 | stat = au_readl(PSC_AC97STAT); | ||
490 | au_sync(); | ||
491 | } while ((stat & PSC_AC97STAT_RB) != 0); | ||
492 | |||
493 | au1xxx_dbdma_reset(db->dmanr); | ||
494 | |||
495 | db->stopped = 1; | ||
496 | |||
497 | spin_unlock_irqrestore(&s->lock, flags); | ||
498 | } | ||
499 | |||
500 | |||
501 | static void | ||
502 | set_xmit_slots(int num_channels) | ||
503 | { | ||
504 | u32 ac97_config, stat; | ||
505 | |||
506 | ac97_config = au_readl(PSC_AC97CFG); | ||
507 | au_sync(); | ||
508 | ac97_config &= ~(PSC_AC97CFG_TXSLOT_MASK | PSC_AC97CFG_DE_ENABLE); | ||
509 | au_writel(ac97_config, PSC_AC97CFG); | ||
510 | au_sync(); | ||
511 | |||
512 | switch (num_channels) { | ||
513 | case 6: /* stereo with surround and center/LFE, | ||
514 | * slots 3,4,6,7,8,9 | ||
515 | */ | ||
516 | ac97_config |= PSC_AC97CFG_TXSLOT_ENA(6); | ||
517 | ac97_config |= PSC_AC97CFG_TXSLOT_ENA(9); | ||
518 | |||
519 | case 4: /* stereo with surround, slots 3,4,7,8 */ | ||
520 | ac97_config |= PSC_AC97CFG_TXSLOT_ENA(7); | ||
521 | ac97_config |= PSC_AC97CFG_TXSLOT_ENA(8); | ||
522 | |||
523 | case 2: /* stereo, slots 3,4 */ | ||
524 | case 1: /* mono */ | ||
525 | ac97_config |= PSC_AC97CFG_TXSLOT_ENA(3); | ||
526 | ac97_config |= PSC_AC97CFG_TXSLOT_ENA(4); | ||
527 | } | ||
528 | |||
529 | au_writel(ac97_config, PSC_AC97CFG); | ||
530 | au_sync(); | ||
531 | |||
532 | ac97_config |= PSC_AC97CFG_DE_ENABLE; | ||
533 | au_writel(ac97_config, PSC_AC97CFG); | ||
534 | au_sync(); | ||
535 | |||
536 | /* Wait for Device ready. | ||
537 | */ | ||
538 | do { | ||
539 | stat = au_readl(PSC_AC97STAT); | ||
540 | au_sync(); | ||
541 | } while ((stat & PSC_AC97STAT_DR) == 0); | ||
542 | } | ||
543 | |||
544 | static void | ||
545 | set_recv_slots(int num_channels) | ||
546 | { | ||
547 | u32 ac97_config, stat; | ||
548 | |||
549 | ac97_config = au_readl(PSC_AC97CFG); | ||
550 | au_sync(); | ||
551 | ac97_config &= ~(PSC_AC97CFG_RXSLOT_MASK | PSC_AC97CFG_DE_ENABLE); | ||
552 | au_writel(ac97_config, PSC_AC97CFG); | ||
553 | au_sync(); | ||
554 | |||
555 | /* Always enable slots 3 and 4 (stereo). Slot 6 is | ||
556 | * optional Mic ADC, which we don't support yet. | ||
557 | */ | ||
558 | ac97_config |= PSC_AC97CFG_RXSLOT_ENA(3); | ||
559 | ac97_config |= PSC_AC97CFG_RXSLOT_ENA(4); | ||
560 | |||
561 | au_writel(ac97_config, PSC_AC97CFG); | ||
562 | au_sync(); | ||
563 | |||
564 | ac97_config |= PSC_AC97CFG_DE_ENABLE; | ||
565 | au_writel(ac97_config, PSC_AC97CFG); | ||
566 | au_sync(); | ||
567 | |||
568 | /* Wait for Device ready. | ||
569 | */ | ||
570 | do { | ||
571 | stat = au_readl(PSC_AC97STAT); | ||
572 | au_sync(); | ||
573 | } while ((stat & PSC_AC97STAT_DR) == 0); | ||
574 | } | ||
575 | |||
576 | /* Hold spinlock for both start_dac() and start_adc() calls */ | ||
577 | static void | ||
578 | start_dac(struct au1550_state *s) | ||
579 | { | ||
580 | struct dmabuf *db = &s->dma_dac; | ||
581 | |||
582 | if (!db->stopped) | ||
583 | return; | ||
584 | |||
585 | set_xmit_slots(db->num_channels); | ||
586 | au_writel(PSC_AC97PCR_TC, PSC_AC97PCR); | ||
587 | au_sync(); | ||
588 | au_writel(PSC_AC97PCR_TS, PSC_AC97PCR); | ||
589 | au_sync(); | ||
590 | |||
591 | au1xxx_dbdma_start(db->dmanr); | ||
592 | |||
593 | db->stopped = 0; | ||
594 | } | ||
595 | |||
596 | static void | ||
597 | start_adc(struct au1550_state *s) | ||
598 | { | ||
599 | struct dmabuf *db = &s->dma_adc; | ||
600 | int i; | ||
601 | |||
602 | if (!db->stopped) | ||
603 | return; | ||
604 | |||
605 | /* Put two buffers on the ring to get things started. | ||
606 | */ | ||
607 | for (i=0; i<2; i++) { | ||
608 | au1xxx_dbdma_put_dest(db->dmanr, virt_to_phys(db->nextIn), | ||
609 | db->dma_fragsize, DDMA_FLAGS_IE); | ||
610 | |||
611 | db->nextIn += db->dma_fragsize; | ||
612 | if (db->nextIn >= db->rawbuf + db->dmasize) | ||
613 | db->nextIn -= db->dmasize; | ||
614 | } | ||
615 | |||
616 | set_recv_slots(db->num_channels); | ||
617 | au1xxx_dbdma_start(db->dmanr); | ||
618 | au_writel(PSC_AC97PCR_RC, PSC_AC97PCR); | ||
619 | au_sync(); | ||
620 | au_writel(PSC_AC97PCR_RS, PSC_AC97PCR); | ||
621 | au_sync(); | ||
622 | |||
623 | db->stopped = 0; | ||
624 | } | ||
625 | |||
626 | static int | ||
627 | prog_dmabuf(struct au1550_state *s, struct dmabuf *db) | ||
628 | { | ||
629 | unsigned user_bytes_per_sec; | ||
630 | unsigned bufs; | ||
631 | unsigned rate = db->sample_rate; | ||
632 | |||
633 | if (!db->rawbuf) { | ||
634 | db->ready = db->mapped = 0; | ||
635 | db->buforder = 5; /* 32 * PAGE_SIZE */ | ||
636 | db->rawbuf = kmalloc((PAGE_SIZE << db->buforder), GFP_KERNEL); | ||
637 | if (!db->rawbuf) | ||
638 | return -ENOMEM; | ||
639 | } | ||
640 | |||
641 | db->cnt_factor = 1; | ||
642 | if (db->sample_size == 8) | ||
643 | db->cnt_factor *= 2; | ||
644 | if (db->num_channels == 1) | ||
645 | db->cnt_factor *= 2; | ||
646 | db->cnt_factor *= db->src_factor; | ||
647 | |||
648 | db->count = 0; | ||
649 | db->dma_qcount = 0; | ||
650 | db->nextIn = db->nextOut = db->rawbuf; | ||
651 | |||
652 | db->user_bytes_per_sample = (db->sample_size>>3) * db->num_channels; | ||
653 | db->dma_bytes_per_sample = 2 * ((db->num_channels == 1) ? | ||
654 | 2 : db->num_channels); | ||
655 | |||
656 | user_bytes_per_sec = rate * db->user_bytes_per_sample; | ||
657 | bufs = PAGE_SIZE << db->buforder; | ||
658 | if (db->ossfragshift) { | ||
659 | if ((1000 << db->ossfragshift) < user_bytes_per_sec) | ||
660 | db->fragshift = ld2(user_bytes_per_sec/1000); | ||
661 | else | ||
662 | db->fragshift = db->ossfragshift; | ||
663 | } else { | ||
664 | db->fragshift = ld2(user_bytes_per_sec / 100 / | ||
665 | (db->subdivision ? db->subdivision : 1)); | ||
666 | if (db->fragshift < 3) | ||
667 | db->fragshift = 3; | ||
668 | } | ||
669 | |||
670 | db->fragsize = 1 << db->fragshift; | ||
671 | db->dma_fragsize = db->fragsize * db->cnt_factor; | ||
672 | db->numfrag = bufs / db->dma_fragsize; | ||
673 | |||
674 | while (db->numfrag < 4 && db->fragshift > 3) { | ||
675 | db->fragshift--; | ||
676 | db->fragsize = 1 << db->fragshift; | ||
677 | db->dma_fragsize = db->fragsize * db->cnt_factor; | ||
678 | db->numfrag = bufs / db->dma_fragsize; | ||
679 | } | ||
680 | |||
681 | if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag) | ||
682 | db->numfrag = db->ossmaxfrags; | ||
683 | |||
684 | db->dmasize = db->dma_fragsize * db->numfrag; | ||
685 | memset(db->rawbuf, 0, bufs); | ||
686 | |||
687 | pr_debug("prog_dmabuf: rate=%d, samplesize=%d, channels=%d\n", | ||
688 | rate, db->sample_size, db->num_channels); | ||
689 | pr_debug("prog_dmabuf: fragsize=%d, cnt_factor=%d, dma_fragsize=%d\n", | ||
690 | db->fragsize, db->cnt_factor, db->dma_fragsize); | ||
691 | pr_debug("prog_dmabuf: numfrag=%d, dmasize=%d\n", db->numfrag, db->dmasize); | ||
692 | |||
693 | db->ready = 1; | ||
694 | return 0; | ||
695 | } | ||
696 | |||
697 | static int | ||
698 | prog_dmabuf_adc(struct au1550_state *s) | ||
699 | { | ||
700 | stop_adc(s); | ||
701 | return prog_dmabuf(s, &s->dma_adc); | ||
702 | |||
703 | } | ||
704 | |||
705 | static int | ||
706 | prog_dmabuf_dac(struct au1550_state *s) | ||
707 | { | ||
708 | stop_dac(s); | ||
709 | return prog_dmabuf(s, &s->dma_dac); | ||
710 | } | ||
711 | |||
712 | |||
713 | static void dac_dma_interrupt(int irq, void *dev_id) | ||
714 | { | ||
715 | struct au1550_state *s = (struct au1550_state *) dev_id; | ||
716 | struct dmabuf *db = &s->dma_dac; | ||
717 | u32 ac97c_stat; | ||
718 | |||
719 | spin_lock(&s->lock); | ||
720 | |||
721 | ac97c_stat = au_readl(PSC_AC97STAT); | ||
722 | if (ac97c_stat & (AC97C_XU | AC97C_XO | AC97C_TE)) | ||
723 | pr_debug("AC97C status = 0x%08x\n", ac97c_stat); | ||
724 | db->dma_qcount--; | ||
725 | |||
726 | if (db->count >= db->fragsize) { | ||
727 | if (au1xxx_dbdma_put_source(db->dmanr, | ||
728 | virt_to_phys(db->nextOut), db->fragsize, | ||
729 | DDMA_FLAGS_IE) == 0) { | ||
730 | err("qcount < 2 and no ring room!"); | ||
731 | } | ||
732 | db->nextOut += db->fragsize; | ||
733 | if (db->nextOut >= db->rawbuf + db->dmasize) | ||
734 | db->nextOut -= db->dmasize; | ||
735 | db->count -= db->fragsize; | ||
736 | db->total_bytes += db->dma_fragsize; | ||
737 | db->dma_qcount++; | ||
738 | } | ||
739 | |||
740 | /* wake up anybody listening */ | ||
741 | if (waitqueue_active(&db->wait)) | ||
742 | wake_up(&db->wait); | ||
743 | |||
744 | spin_unlock(&s->lock); | ||
745 | } | ||
746 | |||
747 | |||
748 | static void adc_dma_interrupt(int irq, void *dev_id) | ||
749 | { | ||
750 | struct au1550_state *s = (struct au1550_state *)dev_id; | ||
751 | struct dmabuf *dp = &s->dma_adc; | ||
752 | u32 obytes; | ||
753 | char *obuf; | ||
754 | |||
755 | spin_lock(&s->lock); | ||
756 | |||
757 | /* Pull the buffer from the dma queue. | ||
758 | */ | ||
759 | au1xxx_dbdma_get_dest(dp->dmanr, (void *)(&obuf), &obytes); | ||
760 | |||
761 | if ((dp->count + obytes) > dp->dmasize) { | ||
762 | /* Overrun. Stop ADC and log the error | ||
763 | */ | ||
764 | spin_unlock(&s->lock); | ||
765 | stop_adc(s); | ||
766 | dp->error++; | ||
767 | err("adc overrun"); | ||
768 | return; | ||
769 | } | ||
770 | |||
771 | /* Put a new empty buffer on the destination DMA. | ||
772 | */ | ||
773 | au1xxx_dbdma_put_dest(dp->dmanr, virt_to_phys(dp->nextIn), | ||
774 | dp->dma_fragsize, DDMA_FLAGS_IE); | ||
775 | |||
776 | dp->nextIn += dp->dma_fragsize; | ||
777 | if (dp->nextIn >= dp->rawbuf + dp->dmasize) | ||
778 | dp->nextIn -= dp->dmasize; | ||
779 | |||
780 | dp->count += obytes; | ||
781 | dp->total_bytes += obytes; | ||
782 | |||
783 | /* wake up anybody listening | ||
784 | */ | ||
785 | if (waitqueue_active(&dp->wait)) | ||
786 | wake_up(&dp->wait); | ||
787 | |||
788 | spin_unlock(&s->lock); | ||
789 | } | ||
790 | |||
791 | static loff_t | ||
792 | au1550_llseek(struct file *file, loff_t offset, int origin) | ||
793 | { | ||
794 | return -ESPIPE; | ||
795 | } | ||
796 | |||
797 | |||
798 | static int | ||
799 | au1550_open_mixdev(struct inode *inode, struct file *file) | ||
800 | { | ||
801 | lock_kernel(); | ||
802 | file->private_data = &au1550_state; | ||
803 | unlock_kernel(); | ||
804 | return 0; | ||
805 | } | ||
806 | |||
807 | static int | ||
808 | au1550_release_mixdev(struct inode *inode, struct file *file) | ||
809 | { | ||
810 | return 0; | ||
811 | } | ||
812 | |||
813 | static int | ||
814 | mixdev_ioctl(struct ac97_codec *codec, unsigned int cmd, | ||
815 | unsigned long arg) | ||
816 | { | ||
817 | return codec->mixer_ioctl(codec, cmd, arg); | ||
818 | } | ||
819 | |||
820 | static long | ||
821 | au1550_ioctl_mixdev(struct file *file, unsigned int cmd, unsigned long arg) | ||
822 | { | ||
823 | struct au1550_state *s = (struct au1550_state *)file->private_data; | ||
824 | struct ac97_codec *codec = s->codec; | ||
825 | int ret; | ||
826 | |||
827 | lock_kernel(); | ||
828 | ret = mixdev_ioctl(codec, cmd, arg); | ||
829 | unlock_kernel(); | ||
830 | |||
831 | return ret; | ||
832 | } | ||
833 | |||
834 | static /*const */ struct file_operations au1550_mixer_fops = { | ||
835 | .owner = THIS_MODULE, | ||
836 | .llseek = au1550_llseek, | ||
837 | .unlocked_ioctl = au1550_ioctl_mixdev, | ||
838 | .open = au1550_open_mixdev, | ||
839 | .release = au1550_release_mixdev, | ||
840 | }; | ||
841 | |||
842 | static int | ||
843 | drain_dac(struct au1550_state *s, int nonblock) | ||
844 | { | ||
845 | unsigned long flags; | ||
846 | int count, tmo; | ||
847 | |||
848 | if (s->dma_dac.mapped || !s->dma_dac.ready || s->dma_dac.stopped) | ||
849 | return 0; | ||
850 | |||
851 | for (;;) { | ||
852 | spin_lock_irqsave(&s->lock, flags); | ||
853 | count = s->dma_dac.count; | ||
854 | spin_unlock_irqrestore(&s->lock, flags); | ||
855 | if (count <= s->dma_dac.fragsize) | ||
856 | break; | ||
857 | if (signal_pending(current)) | ||
858 | break; | ||
859 | if (nonblock) | ||
860 | return -EBUSY; | ||
861 | tmo = 1000 * count / (s->no_vra ? | ||
862 | 48000 : s->dma_dac.sample_rate); | ||
863 | tmo /= s->dma_dac.dma_bytes_per_sample; | ||
864 | au1550_delay(tmo); | ||
865 | } | ||
866 | if (signal_pending(current)) | ||
867 | return -ERESTARTSYS; | ||
868 | return 0; | ||
869 | } | ||
870 | |||
871 | static inline u8 S16_TO_U8(s16 ch) | ||
872 | { | ||
873 | return (u8) (ch >> 8) + 0x80; | ||
874 | } | ||
875 | static inline s16 U8_TO_S16(u8 ch) | ||
876 | { | ||
877 | return (s16) (ch - 0x80) << 8; | ||
878 | } | ||
879 | |||
880 | /* | ||
881 | * Translates user samples to dma buffer suitable for AC'97 DAC data: | ||
882 | * If mono, copy left channel to right channel in dma buffer. | ||
883 | * If 8 bit samples, cvt to 16-bit before writing to dma buffer. | ||
884 | * If interpolating (no VRA), duplicate every audio frame src_factor times. | ||
885 | */ | ||
886 | static int | ||
887 | translate_from_user(struct dmabuf *db, char* dmabuf, char* userbuf, | ||
888 | int dmacount) | ||
889 | { | ||
890 | int sample, i; | ||
891 | int interp_bytes_per_sample; | ||
892 | int num_samples; | ||
893 | int mono = (db->num_channels == 1); | ||
894 | char usersample[12]; | ||
895 | s16 ch, dmasample[6]; | ||
896 | |||
897 | if (db->sample_size == 16 && !mono && db->src_factor == 1) { | ||
898 | /* no translation necessary, just copy | ||
899 | */ | ||
900 | if (copy_from_user(dmabuf, userbuf, dmacount)) | ||
901 | return -EFAULT; | ||
902 | return dmacount; | ||
903 | } | ||
904 | |||
905 | interp_bytes_per_sample = db->dma_bytes_per_sample * db->src_factor; | ||
906 | num_samples = dmacount / interp_bytes_per_sample; | ||
907 | |||
908 | for (sample = 0; sample < num_samples; sample++) { | ||
909 | if (copy_from_user(usersample, userbuf, | ||
910 | db->user_bytes_per_sample)) { | ||
911 | return -EFAULT; | ||
912 | } | ||
913 | |||
914 | for (i = 0; i < db->num_channels; i++) { | ||
915 | if (db->sample_size == 8) | ||
916 | ch = U8_TO_S16(usersample[i]); | ||
917 | else | ||
918 | ch = *((s16 *) (&usersample[i * 2])); | ||
919 | dmasample[i] = ch; | ||
920 | if (mono) | ||
921 | dmasample[i + 1] = ch; /* right channel */ | ||
922 | } | ||
923 | |||
924 | /* duplicate every audio frame src_factor times | ||
925 | */ | ||
926 | for (i = 0; i < db->src_factor; i++) | ||
927 | memcpy(dmabuf, dmasample, db->dma_bytes_per_sample); | ||
928 | |||
929 | userbuf += db->user_bytes_per_sample; | ||
930 | dmabuf += interp_bytes_per_sample; | ||
931 | } | ||
932 | |||
933 | return num_samples * interp_bytes_per_sample; | ||
934 | } | ||
935 | |||
936 | /* | ||
937 | * Translates AC'97 ADC samples to user buffer: | ||
938 | * If mono, send only left channel to user buffer. | ||
939 | * If 8 bit samples, cvt from 16 to 8 bit before writing to user buffer. | ||
940 | * If decimating (no VRA), skip over src_factor audio frames. | ||
941 | */ | ||
942 | static int | ||
943 | translate_to_user(struct dmabuf *db, char* userbuf, char* dmabuf, | ||
944 | int dmacount) | ||
945 | { | ||
946 | int sample, i; | ||
947 | int interp_bytes_per_sample; | ||
948 | int num_samples; | ||
949 | int mono = (db->num_channels == 1); | ||
950 | char usersample[12]; | ||
951 | |||
952 | if (db->sample_size == 16 && !mono && db->src_factor == 1) { | ||
953 | /* no translation necessary, just copy | ||
954 | */ | ||
955 | if (copy_to_user(userbuf, dmabuf, dmacount)) | ||
956 | return -EFAULT; | ||
957 | return dmacount; | ||
958 | } | ||
959 | |||
960 | interp_bytes_per_sample = db->dma_bytes_per_sample * db->src_factor; | ||
961 | num_samples = dmacount / interp_bytes_per_sample; | ||
962 | |||
963 | for (sample = 0; sample < num_samples; sample++) { | ||
964 | for (i = 0; i < db->num_channels; i++) { | ||
965 | if (db->sample_size == 8) | ||
966 | usersample[i] = | ||
967 | S16_TO_U8(*((s16 *) (&dmabuf[i * 2]))); | ||
968 | else | ||
969 | *((s16 *) (&usersample[i * 2])) = | ||
970 | *((s16 *) (&dmabuf[i * 2])); | ||
971 | } | ||
972 | |||
973 | if (copy_to_user(userbuf, usersample, | ||
974 | db->user_bytes_per_sample)) { | ||
975 | return -EFAULT; | ||
976 | } | ||
977 | |||
978 | userbuf += db->user_bytes_per_sample; | ||
979 | dmabuf += interp_bytes_per_sample; | ||
980 | } | ||
981 | |||
982 | return num_samples * interp_bytes_per_sample; | ||
983 | } | ||
984 | |||
985 | /* | ||
986 | * Copy audio data to/from user buffer from/to dma buffer, taking care | ||
987 | * that we wrap when reading/writing the dma buffer. Returns actual byte | ||
988 | * count written to or read from the dma buffer. | ||
989 | */ | ||
990 | static int | ||
991 | copy_dmabuf_user(struct dmabuf *db, char* userbuf, int count, int to_user) | ||
992 | { | ||
993 | char *bufptr = to_user ? db->nextOut : db->nextIn; | ||
994 | char *bufend = db->rawbuf + db->dmasize; | ||
995 | int cnt, ret; | ||
996 | |||
997 | if (bufptr + count > bufend) { | ||
998 | int partial = (int) (bufend - bufptr); | ||
999 | if (to_user) { | ||
1000 | if ((cnt = translate_to_user(db, userbuf, | ||
1001 | bufptr, partial)) < 0) | ||
1002 | return cnt; | ||
1003 | ret = cnt; | ||
1004 | if ((cnt = translate_to_user(db, userbuf + partial, | ||
1005 | db->rawbuf, | ||
1006 | count - partial)) < 0) | ||
1007 | return cnt; | ||
1008 | ret += cnt; | ||
1009 | } else { | ||
1010 | if ((cnt = translate_from_user(db, bufptr, userbuf, | ||
1011 | partial)) < 0) | ||
1012 | return cnt; | ||
1013 | ret = cnt; | ||
1014 | if ((cnt = translate_from_user(db, db->rawbuf, | ||
1015 | userbuf + partial, | ||
1016 | count - partial)) < 0) | ||
1017 | return cnt; | ||
1018 | ret += cnt; | ||
1019 | } | ||
1020 | } else { | ||
1021 | if (to_user) | ||
1022 | ret = translate_to_user(db, userbuf, bufptr, count); | ||
1023 | else | ||
1024 | ret = translate_from_user(db, bufptr, userbuf, count); | ||
1025 | } | ||
1026 | |||
1027 | return ret; | ||
1028 | } | ||
1029 | |||
1030 | |||
1031 | static ssize_t | ||
1032 | au1550_read(struct file *file, char *buffer, size_t count, loff_t *ppos) | ||
1033 | { | ||
1034 | struct au1550_state *s = (struct au1550_state *)file->private_data; | ||
1035 | struct dmabuf *db = &s->dma_adc; | ||
1036 | DECLARE_WAITQUEUE(wait, current); | ||
1037 | ssize_t ret; | ||
1038 | unsigned long flags; | ||
1039 | int cnt, usercnt, avail; | ||
1040 | |||
1041 | if (db->mapped) | ||
1042 | return -ENXIO; | ||
1043 | if (!access_ok(VERIFY_WRITE, buffer, count)) | ||
1044 | return -EFAULT; | ||
1045 | ret = 0; | ||
1046 | |||
1047 | count *= db->cnt_factor; | ||
1048 | |||
1049 | mutex_lock(&s->sem); | ||
1050 | add_wait_queue(&db->wait, &wait); | ||
1051 | |||
1052 | while (count > 0) { | ||
1053 | /* wait for samples in ADC dma buffer | ||
1054 | */ | ||
1055 | do { | ||
1056 | spin_lock_irqsave(&s->lock, flags); | ||
1057 | if (db->stopped) | ||
1058 | start_adc(s); | ||
1059 | avail = db->count; | ||
1060 | if (avail <= 0) | ||
1061 | __set_current_state(TASK_INTERRUPTIBLE); | ||
1062 | spin_unlock_irqrestore(&s->lock, flags); | ||
1063 | if (avail <= 0) { | ||
1064 | if (file->f_flags & O_NONBLOCK) { | ||
1065 | if (!ret) | ||
1066 | ret = -EAGAIN; | ||
1067 | goto out; | ||
1068 | } | ||
1069 | mutex_unlock(&s->sem); | ||
1070 | schedule(); | ||
1071 | if (signal_pending(current)) { | ||
1072 | if (!ret) | ||
1073 | ret = -ERESTARTSYS; | ||
1074 | goto out2; | ||
1075 | } | ||
1076 | mutex_lock(&s->sem); | ||
1077 | } | ||
1078 | } while (avail <= 0); | ||
1079 | |||
1080 | /* copy from nextOut to user | ||
1081 | */ | ||
1082 | if ((cnt = copy_dmabuf_user(db, buffer, | ||
1083 | count > avail ? | ||
1084 | avail : count, 1)) < 0) { | ||
1085 | if (!ret) | ||
1086 | ret = -EFAULT; | ||
1087 | goto out; | ||
1088 | } | ||
1089 | |||
1090 | spin_lock_irqsave(&s->lock, flags); | ||
1091 | db->count -= cnt; | ||
1092 | db->nextOut += cnt; | ||
1093 | if (db->nextOut >= db->rawbuf + db->dmasize) | ||
1094 | db->nextOut -= db->dmasize; | ||
1095 | spin_unlock_irqrestore(&s->lock, flags); | ||
1096 | |||
1097 | count -= cnt; | ||
1098 | usercnt = cnt / db->cnt_factor; | ||
1099 | buffer += usercnt; | ||
1100 | ret += usercnt; | ||
1101 | } /* while (count > 0) */ | ||
1102 | |||
1103 | out: | ||
1104 | mutex_unlock(&s->sem); | ||
1105 | out2: | ||
1106 | remove_wait_queue(&db->wait, &wait); | ||
1107 | set_current_state(TASK_RUNNING); | ||
1108 | return ret; | ||
1109 | } | ||
1110 | |||
1111 | static ssize_t | ||
1112 | au1550_write(struct file *file, const char *buffer, size_t count, loff_t * ppos) | ||
1113 | { | ||
1114 | struct au1550_state *s = (struct au1550_state *)file->private_data; | ||
1115 | struct dmabuf *db = &s->dma_dac; | ||
1116 | DECLARE_WAITQUEUE(wait, current); | ||
1117 | ssize_t ret = 0; | ||
1118 | unsigned long flags; | ||
1119 | int cnt, usercnt, avail; | ||
1120 | |||
1121 | pr_debug("write: count=%d\n", count); | ||
1122 | |||
1123 | if (db->mapped) | ||
1124 | return -ENXIO; | ||
1125 | if (!access_ok(VERIFY_READ, buffer, count)) | ||
1126 | return -EFAULT; | ||
1127 | |||
1128 | count *= db->cnt_factor; | ||
1129 | |||
1130 | mutex_lock(&s->sem); | ||
1131 | add_wait_queue(&db->wait, &wait); | ||
1132 | |||
1133 | while (count > 0) { | ||
1134 | /* wait for space in playback buffer | ||
1135 | */ | ||
1136 | do { | ||
1137 | spin_lock_irqsave(&s->lock, flags); | ||
1138 | avail = (int) db->dmasize - db->count; | ||
1139 | if (avail <= 0) | ||
1140 | __set_current_state(TASK_INTERRUPTIBLE); | ||
1141 | spin_unlock_irqrestore(&s->lock, flags); | ||
1142 | if (avail <= 0) { | ||
1143 | if (file->f_flags & O_NONBLOCK) { | ||
1144 | if (!ret) | ||
1145 | ret = -EAGAIN; | ||
1146 | goto out; | ||
1147 | } | ||
1148 | mutex_unlock(&s->sem); | ||
1149 | schedule(); | ||
1150 | if (signal_pending(current)) { | ||
1151 | if (!ret) | ||
1152 | ret = -ERESTARTSYS; | ||
1153 | goto out2; | ||
1154 | } | ||
1155 | mutex_lock(&s->sem); | ||
1156 | } | ||
1157 | } while (avail <= 0); | ||
1158 | |||
1159 | /* copy from user to nextIn | ||
1160 | */ | ||
1161 | if ((cnt = copy_dmabuf_user(db, (char *) buffer, | ||
1162 | count > avail ? | ||
1163 | avail : count, 0)) < 0) { | ||
1164 | if (!ret) | ||
1165 | ret = -EFAULT; | ||
1166 | goto out; | ||
1167 | } | ||
1168 | |||
1169 | spin_lock_irqsave(&s->lock, flags); | ||
1170 | db->count += cnt; | ||
1171 | db->nextIn += cnt; | ||
1172 | if (db->nextIn >= db->rawbuf + db->dmasize) | ||
1173 | db->nextIn -= db->dmasize; | ||
1174 | |||
1175 | /* If the data is available, we want to keep two buffers | ||
1176 | * on the dma queue. If the queue count reaches zero, | ||
1177 | * we know the dma has stopped. | ||
1178 | */ | ||
1179 | while ((db->dma_qcount < 2) && (db->count >= db->fragsize)) { | ||
1180 | if (au1xxx_dbdma_put_source(db->dmanr, | ||
1181 | virt_to_phys(db->nextOut), db->fragsize, | ||
1182 | DDMA_FLAGS_IE) == 0) { | ||
1183 | err("qcount < 2 and no ring room!"); | ||
1184 | } | ||
1185 | db->nextOut += db->fragsize; | ||
1186 | if (db->nextOut >= db->rawbuf + db->dmasize) | ||
1187 | db->nextOut -= db->dmasize; | ||
1188 | db->total_bytes += db->dma_fragsize; | ||
1189 | if (db->dma_qcount == 0) | ||
1190 | start_dac(s); | ||
1191 | db->dma_qcount++; | ||
1192 | } | ||
1193 | spin_unlock_irqrestore(&s->lock, flags); | ||
1194 | |||
1195 | count -= cnt; | ||
1196 | usercnt = cnt / db->cnt_factor; | ||
1197 | buffer += usercnt; | ||
1198 | ret += usercnt; | ||
1199 | } /* while (count > 0) */ | ||
1200 | |||
1201 | out: | ||
1202 | mutex_unlock(&s->sem); | ||
1203 | out2: | ||
1204 | remove_wait_queue(&db->wait, &wait); | ||
1205 | set_current_state(TASK_RUNNING); | ||
1206 | return ret; | ||
1207 | } | ||
1208 | |||
1209 | |||
1210 | /* No kernel lock - we have our own spinlock */ | ||
1211 | static unsigned int | ||
1212 | au1550_poll(struct file *file, struct poll_table_struct *wait) | ||
1213 | { | ||
1214 | struct au1550_state *s = (struct au1550_state *)file->private_data; | ||
1215 | unsigned long flags; | ||
1216 | unsigned int mask = 0; | ||
1217 | |||
1218 | if (file->f_mode & FMODE_WRITE) { | ||
1219 | if (!s->dma_dac.ready) | ||
1220 | return 0; | ||
1221 | poll_wait(file, &s->dma_dac.wait, wait); | ||
1222 | } | ||
1223 | if (file->f_mode & FMODE_READ) { | ||
1224 | if (!s->dma_adc.ready) | ||
1225 | return 0; | ||
1226 | poll_wait(file, &s->dma_adc.wait, wait); | ||
1227 | } | ||
1228 | |||
1229 | spin_lock_irqsave(&s->lock, flags); | ||
1230 | |||
1231 | if (file->f_mode & FMODE_READ) { | ||
1232 | if (s->dma_adc.count >= (signed)s->dma_adc.dma_fragsize) | ||
1233 | mask |= POLLIN | POLLRDNORM; | ||
1234 | } | ||
1235 | if (file->f_mode & FMODE_WRITE) { | ||
1236 | if (s->dma_dac.mapped) { | ||
1237 | if (s->dma_dac.count >= | ||
1238 | (signed)s->dma_dac.dma_fragsize) | ||
1239 | mask |= POLLOUT | POLLWRNORM; | ||
1240 | } else { | ||
1241 | if ((signed) s->dma_dac.dmasize >= | ||
1242 | s->dma_dac.count + (signed)s->dma_dac.dma_fragsize) | ||
1243 | mask |= POLLOUT | POLLWRNORM; | ||
1244 | } | ||
1245 | } | ||
1246 | spin_unlock_irqrestore(&s->lock, flags); | ||
1247 | return mask; | ||
1248 | } | ||
1249 | |||
1250 | static int | ||
1251 | au1550_mmap(struct file *file, struct vm_area_struct *vma) | ||
1252 | { | ||
1253 | struct au1550_state *s = (struct au1550_state *)file->private_data; | ||
1254 | struct dmabuf *db; | ||
1255 | unsigned long size; | ||
1256 | int ret = 0; | ||
1257 | |||
1258 | lock_kernel(); | ||
1259 | mutex_lock(&s->sem); | ||
1260 | if (vma->vm_flags & VM_WRITE) | ||
1261 | db = &s->dma_dac; | ||
1262 | else if (vma->vm_flags & VM_READ) | ||
1263 | db = &s->dma_adc; | ||
1264 | else { | ||
1265 | ret = -EINVAL; | ||
1266 | goto out; | ||
1267 | } | ||
1268 | if (vma->vm_pgoff != 0) { | ||
1269 | ret = -EINVAL; | ||
1270 | goto out; | ||
1271 | } | ||
1272 | size = vma->vm_end - vma->vm_start; | ||
1273 | if (size > (PAGE_SIZE << db->buforder)) { | ||
1274 | ret = -EINVAL; | ||
1275 | goto out; | ||
1276 | } | ||
1277 | if (remap_pfn_range(vma, vma->vm_start, page_to_pfn(virt_to_page(db->rawbuf)), | ||
1278 | size, vma->vm_page_prot)) { | ||
1279 | ret = -EAGAIN; | ||
1280 | goto out; | ||
1281 | } | ||
1282 | vma->vm_flags &= ~VM_IO; | ||
1283 | db->mapped = 1; | ||
1284 | out: | ||
1285 | mutex_unlock(&s->sem); | ||
1286 | unlock_kernel(); | ||
1287 | return ret; | ||
1288 | } | ||
1289 | |||
1290 | #ifdef DEBUG | ||
1291 | static struct ioctl_str_t { | ||
1292 | unsigned int cmd; | ||
1293 | const char *str; | ||
1294 | } ioctl_str[] = { | ||
1295 | {SNDCTL_DSP_RESET, "SNDCTL_DSP_RESET"}, | ||
1296 | {SNDCTL_DSP_SYNC, "SNDCTL_DSP_SYNC"}, | ||
1297 | {SNDCTL_DSP_SPEED, "SNDCTL_DSP_SPEED"}, | ||
1298 | {SNDCTL_DSP_STEREO, "SNDCTL_DSP_STEREO"}, | ||
1299 | {SNDCTL_DSP_GETBLKSIZE, "SNDCTL_DSP_GETBLKSIZE"}, | ||
1300 | {SNDCTL_DSP_SAMPLESIZE, "SNDCTL_DSP_SAMPLESIZE"}, | ||
1301 | {SNDCTL_DSP_CHANNELS, "SNDCTL_DSP_CHANNELS"}, | ||
1302 | {SOUND_PCM_WRITE_CHANNELS, "SOUND_PCM_WRITE_CHANNELS"}, | ||
1303 | {SOUND_PCM_WRITE_FILTER, "SOUND_PCM_WRITE_FILTER"}, | ||
1304 | {SNDCTL_DSP_POST, "SNDCTL_DSP_POST"}, | ||
1305 | {SNDCTL_DSP_SUBDIVIDE, "SNDCTL_DSP_SUBDIVIDE"}, | ||
1306 | {SNDCTL_DSP_SETFRAGMENT, "SNDCTL_DSP_SETFRAGMENT"}, | ||
1307 | {SNDCTL_DSP_GETFMTS, "SNDCTL_DSP_GETFMTS"}, | ||
1308 | {SNDCTL_DSP_SETFMT, "SNDCTL_DSP_SETFMT"}, | ||
1309 | {SNDCTL_DSP_GETOSPACE, "SNDCTL_DSP_GETOSPACE"}, | ||
1310 | {SNDCTL_DSP_GETISPACE, "SNDCTL_DSP_GETISPACE"}, | ||
1311 | {SNDCTL_DSP_NONBLOCK, "SNDCTL_DSP_NONBLOCK"}, | ||
1312 | {SNDCTL_DSP_GETCAPS, "SNDCTL_DSP_GETCAPS"}, | ||
1313 | {SNDCTL_DSP_GETTRIGGER, "SNDCTL_DSP_GETTRIGGER"}, | ||
1314 | {SNDCTL_DSP_SETTRIGGER, "SNDCTL_DSP_SETTRIGGER"}, | ||
1315 | {SNDCTL_DSP_GETIPTR, "SNDCTL_DSP_GETIPTR"}, | ||
1316 | {SNDCTL_DSP_GETOPTR, "SNDCTL_DSP_GETOPTR"}, | ||
1317 | {SNDCTL_DSP_MAPINBUF, "SNDCTL_DSP_MAPINBUF"}, | ||
1318 | {SNDCTL_DSP_MAPOUTBUF, "SNDCTL_DSP_MAPOUTBUF"}, | ||
1319 | {SNDCTL_DSP_SETSYNCRO, "SNDCTL_DSP_SETSYNCRO"}, | ||
1320 | {SNDCTL_DSP_SETDUPLEX, "SNDCTL_DSP_SETDUPLEX"}, | ||
1321 | {SNDCTL_DSP_GETODELAY, "SNDCTL_DSP_GETODELAY"}, | ||
1322 | {SNDCTL_DSP_GETCHANNELMASK, "SNDCTL_DSP_GETCHANNELMASK"}, | ||
1323 | {SNDCTL_DSP_BIND_CHANNEL, "SNDCTL_DSP_BIND_CHANNEL"}, | ||
1324 | {OSS_GETVERSION, "OSS_GETVERSION"}, | ||
1325 | {SOUND_PCM_READ_RATE, "SOUND_PCM_READ_RATE"}, | ||
1326 | {SOUND_PCM_READ_CHANNELS, "SOUND_PCM_READ_CHANNELS"}, | ||
1327 | {SOUND_PCM_READ_BITS, "SOUND_PCM_READ_BITS"}, | ||
1328 | {SOUND_PCM_READ_FILTER, "SOUND_PCM_READ_FILTER"} | ||
1329 | }; | ||
1330 | #endif | ||
1331 | |||
1332 | static int | ||
1333 | dma_count_done(struct dmabuf *db) | ||
1334 | { | ||
1335 | if (db->stopped) | ||
1336 | return 0; | ||
1337 | |||
1338 | return db->dma_fragsize - au1xxx_get_dma_residue(db->dmanr); | ||
1339 | } | ||
1340 | |||
1341 | |||
1342 | static int | ||
1343 | au1550_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | ||
1344 | { | ||
1345 | struct au1550_state *s = (struct au1550_state *)file->private_data; | ||
1346 | unsigned long flags; | ||
1347 | audio_buf_info abinfo; | ||
1348 | count_info cinfo; | ||
1349 | int count; | ||
1350 | int val, mapped, ret, diff; | ||
1351 | |||
1352 | mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) || | ||
1353 | ((file->f_mode & FMODE_READ) && s->dma_adc.mapped); | ||
1354 | |||
1355 | #ifdef DEBUG | ||
1356 | for (count = 0; count < ARRAY_SIZE(ioctl_str); count++) { | ||
1357 | if (ioctl_str[count].cmd == cmd) | ||
1358 | break; | ||
1359 | } | ||
1360 | if (count < ARRAY_SIZE(ioctl_str)) | ||
1361 | pr_debug("ioctl %s, arg=0x%lxn", ioctl_str[count].str, arg); | ||
1362 | else | ||
1363 | pr_debug("ioctl 0x%x unknown, arg=0x%lx\n", cmd, arg); | ||
1364 | #endif | ||
1365 | |||
1366 | switch (cmd) { | ||
1367 | case OSS_GETVERSION: | ||
1368 | return put_user(SOUND_VERSION, (int *) arg); | ||
1369 | |||
1370 | case SNDCTL_DSP_SYNC: | ||
1371 | if (file->f_mode & FMODE_WRITE) | ||
1372 | return drain_dac(s, file->f_flags & O_NONBLOCK); | ||
1373 | return 0; | ||
1374 | |||
1375 | case SNDCTL_DSP_SETDUPLEX: | ||
1376 | return 0; | ||
1377 | |||
1378 | case SNDCTL_DSP_GETCAPS: | ||
1379 | return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | | ||
1380 | DSP_CAP_TRIGGER | DSP_CAP_MMAP, (int *)arg); | ||
1381 | |||
1382 | case SNDCTL_DSP_RESET: | ||
1383 | if (file->f_mode & FMODE_WRITE) { | ||
1384 | stop_dac(s); | ||
1385 | synchronize_irq(); | ||
1386 | s->dma_dac.count = s->dma_dac.total_bytes = 0; | ||
1387 | s->dma_dac.nextIn = s->dma_dac.nextOut = | ||
1388 | s->dma_dac.rawbuf; | ||
1389 | } | ||
1390 | if (file->f_mode & FMODE_READ) { | ||
1391 | stop_adc(s); | ||
1392 | synchronize_irq(); | ||
1393 | s->dma_adc.count = s->dma_adc.total_bytes = 0; | ||
1394 | s->dma_adc.nextIn = s->dma_adc.nextOut = | ||
1395 | s->dma_adc.rawbuf; | ||
1396 | } | ||
1397 | return 0; | ||
1398 | |||
1399 | case SNDCTL_DSP_SPEED: | ||
1400 | if (get_user(val, (int *) arg)) | ||
1401 | return -EFAULT; | ||
1402 | if (val >= 0) { | ||
1403 | if (file->f_mode & FMODE_READ) { | ||
1404 | stop_adc(s); | ||
1405 | set_adc_rate(s, val); | ||
1406 | } | ||
1407 | if (file->f_mode & FMODE_WRITE) { | ||
1408 | stop_dac(s); | ||
1409 | set_dac_rate(s, val); | ||
1410 | } | ||
1411 | if (s->open_mode & FMODE_READ) | ||
1412 | if ((ret = prog_dmabuf_adc(s))) | ||
1413 | return ret; | ||
1414 | if (s->open_mode & FMODE_WRITE) | ||
1415 | if ((ret = prog_dmabuf_dac(s))) | ||
1416 | return ret; | ||
1417 | } | ||
1418 | return put_user((file->f_mode & FMODE_READ) ? | ||
1419 | s->dma_adc.sample_rate : | ||
1420 | s->dma_dac.sample_rate, | ||
1421 | (int *)arg); | ||
1422 | |||
1423 | case SNDCTL_DSP_STEREO: | ||
1424 | if (get_user(val, (int *) arg)) | ||
1425 | return -EFAULT; | ||
1426 | if (file->f_mode & FMODE_READ) { | ||
1427 | stop_adc(s); | ||
1428 | s->dma_adc.num_channels = val ? 2 : 1; | ||
1429 | if ((ret = prog_dmabuf_adc(s))) | ||
1430 | return ret; | ||
1431 | } | ||
1432 | if (file->f_mode & FMODE_WRITE) { | ||
1433 | stop_dac(s); | ||
1434 | s->dma_dac.num_channels = val ? 2 : 1; | ||
1435 | if (s->codec_ext_caps & AC97_EXT_DACS) { | ||
1436 | /* disable surround and center/lfe in AC'97 | ||
1437 | */ | ||
1438 | u16 ext_stat = rdcodec(s->codec, | ||
1439 | AC97_EXTENDED_STATUS); | ||
1440 | wrcodec(s->codec, AC97_EXTENDED_STATUS, | ||
1441 | ext_stat | (AC97_EXTSTAT_PRI | | ||
1442 | AC97_EXTSTAT_PRJ | | ||
1443 | AC97_EXTSTAT_PRK)); | ||
1444 | } | ||
1445 | if ((ret = prog_dmabuf_dac(s))) | ||
1446 | return ret; | ||
1447 | } | ||
1448 | return 0; | ||
1449 | |||
1450 | case SNDCTL_DSP_CHANNELS: | ||
1451 | if (get_user(val, (int *) arg)) | ||
1452 | return -EFAULT; | ||
1453 | if (val != 0) { | ||
1454 | if (file->f_mode & FMODE_READ) { | ||
1455 | if (val < 0 || val > 2) | ||
1456 | return -EINVAL; | ||
1457 | stop_adc(s); | ||
1458 | s->dma_adc.num_channels = val; | ||
1459 | if ((ret = prog_dmabuf_adc(s))) | ||
1460 | return ret; | ||
1461 | } | ||
1462 | if (file->f_mode & FMODE_WRITE) { | ||
1463 | switch (val) { | ||
1464 | case 1: | ||
1465 | case 2: | ||
1466 | break; | ||
1467 | case 3: | ||
1468 | case 5: | ||
1469 | return -EINVAL; | ||
1470 | case 4: | ||
1471 | if (!(s->codec_ext_caps & | ||
1472 | AC97_EXTID_SDAC)) | ||
1473 | return -EINVAL; | ||
1474 | break; | ||
1475 | case 6: | ||
1476 | if ((s->codec_ext_caps & | ||
1477 | AC97_EXT_DACS) != AC97_EXT_DACS) | ||
1478 | return -EINVAL; | ||
1479 | break; | ||
1480 | default: | ||
1481 | return -EINVAL; | ||
1482 | } | ||
1483 | |||
1484 | stop_dac(s); | ||
1485 | if (val <= 2 && | ||
1486 | (s->codec_ext_caps & AC97_EXT_DACS)) { | ||
1487 | /* disable surround and center/lfe | ||
1488 | * channels in AC'97 | ||
1489 | */ | ||
1490 | u16 ext_stat = | ||
1491 | rdcodec(s->codec, | ||
1492 | AC97_EXTENDED_STATUS); | ||
1493 | wrcodec(s->codec, | ||
1494 | AC97_EXTENDED_STATUS, | ||
1495 | ext_stat | (AC97_EXTSTAT_PRI | | ||
1496 | AC97_EXTSTAT_PRJ | | ||
1497 | AC97_EXTSTAT_PRK)); | ||
1498 | } else if (val >= 4) { | ||
1499 | /* enable surround, center/lfe | ||
1500 | * channels in AC'97 | ||
1501 | */ | ||
1502 | u16 ext_stat = | ||
1503 | rdcodec(s->codec, | ||
1504 | AC97_EXTENDED_STATUS); | ||
1505 | ext_stat &= ~AC97_EXTSTAT_PRJ; | ||
1506 | if (val == 6) | ||
1507 | ext_stat &= | ||
1508 | ~(AC97_EXTSTAT_PRI | | ||
1509 | AC97_EXTSTAT_PRK); | ||
1510 | wrcodec(s->codec, | ||
1511 | AC97_EXTENDED_STATUS, | ||
1512 | ext_stat); | ||
1513 | } | ||
1514 | |||
1515 | s->dma_dac.num_channels = val; | ||
1516 | if ((ret = prog_dmabuf_dac(s))) | ||
1517 | return ret; | ||
1518 | } | ||
1519 | } | ||
1520 | return put_user(val, (int *) arg); | ||
1521 | |||
1522 | case SNDCTL_DSP_GETFMTS: /* Returns a mask */ | ||
1523 | return put_user(AFMT_S16_LE | AFMT_U8, (int *) arg); | ||
1524 | |||
1525 | case SNDCTL_DSP_SETFMT: /* Selects ONE fmt */ | ||
1526 | if (get_user(val, (int *) arg)) | ||
1527 | return -EFAULT; | ||
1528 | if (val != AFMT_QUERY) { | ||
1529 | if (file->f_mode & FMODE_READ) { | ||
1530 | stop_adc(s); | ||
1531 | if (val == AFMT_S16_LE) | ||
1532 | s->dma_adc.sample_size = 16; | ||
1533 | else { | ||
1534 | val = AFMT_U8; | ||
1535 | s->dma_adc.sample_size = 8; | ||
1536 | } | ||
1537 | if ((ret = prog_dmabuf_adc(s))) | ||
1538 | return ret; | ||
1539 | } | ||
1540 | if (file->f_mode & FMODE_WRITE) { | ||
1541 | stop_dac(s); | ||
1542 | if (val == AFMT_S16_LE) | ||
1543 | s->dma_dac.sample_size = 16; | ||
1544 | else { | ||
1545 | val = AFMT_U8; | ||
1546 | s->dma_dac.sample_size = 8; | ||
1547 | } | ||
1548 | if ((ret = prog_dmabuf_dac(s))) | ||
1549 | return ret; | ||
1550 | } | ||
1551 | } else { | ||
1552 | if (file->f_mode & FMODE_READ) | ||
1553 | val = (s->dma_adc.sample_size == 16) ? | ||
1554 | AFMT_S16_LE : AFMT_U8; | ||
1555 | else | ||
1556 | val = (s->dma_dac.sample_size == 16) ? | ||
1557 | AFMT_S16_LE : AFMT_U8; | ||
1558 | } | ||
1559 | return put_user(val, (int *) arg); | ||
1560 | |||
1561 | case SNDCTL_DSP_POST: | ||
1562 | return 0; | ||
1563 | |||
1564 | case SNDCTL_DSP_GETTRIGGER: | ||
1565 | val = 0; | ||
1566 | spin_lock_irqsave(&s->lock, flags); | ||
1567 | if (file->f_mode & FMODE_READ && !s->dma_adc.stopped) | ||
1568 | val |= PCM_ENABLE_INPUT; | ||
1569 | if (file->f_mode & FMODE_WRITE && !s->dma_dac.stopped) | ||
1570 | val |= PCM_ENABLE_OUTPUT; | ||
1571 | spin_unlock_irqrestore(&s->lock, flags); | ||
1572 | return put_user(val, (int *) arg); | ||
1573 | |||
1574 | case SNDCTL_DSP_SETTRIGGER: | ||
1575 | if (get_user(val, (int *) arg)) | ||
1576 | return -EFAULT; | ||
1577 | if (file->f_mode & FMODE_READ) { | ||
1578 | if (val & PCM_ENABLE_INPUT) { | ||
1579 | spin_lock_irqsave(&s->lock, flags); | ||
1580 | start_adc(s); | ||
1581 | spin_unlock_irqrestore(&s->lock, flags); | ||
1582 | } else | ||
1583 | stop_adc(s); | ||
1584 | } | ||
1585 | if (file->f_mode & FMODE_WRITE) { | ||
1586 | if (val & PCM_ENABLE_OUTPUT) { | ||
1587 | spin_lock_irqsave(&s->lock, flags); | ||
1588 | start_dac(s); | ||
1589 | spin_unlock_irqrestore(&s->lock, flags); | ||
1590 | } else | ||
1591 | stop_dac(s); | ||
1592 | } | ||
1593 | return 0; | ||
1594 | |||
1595 | case SNDCTL_DSP_GETOSPACE: | ||
1596 | if (!(file->f_mode & FMODE_WRITE)) | ||
1597 | return -EINVAL; | ||
1598 | abinfo.fragsize = s->dma_dac.fragsize; | ||
1599 | spin_lock_irqsave(&s->lock, flags); | ||
1600 | count = s->dma_dac.count; | ||
1601 | count -= dma_count_done(&s->dma_dac); | ||
1602 | spin_unlock_irqrestore(&s->lock, flags); | ||
1603 | if (count < 0) | ||
1604 | count = 0; | ||
1605 | abinfo.bytes = (s->dma_dac.dmasize - count) / | ||
1606 | s->dma_dac.cnt_factor; | ||
1607 | abinfo.fragstotal = s->dma_dac.numfrag; | ||
1608 | abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift; | ||
1609 | pr_debug("ioctl SNDCTL_DSP_GETOSPACE: bytes=%d, fragments=%d\n", abinfo.bytes, abinfo.fragments); | ||
1610 | return copy_to_user((void *) arg, &abinfo, | ||
1611 | sizeof(abinfo)) ? -EFAULT : 0; | ||
1612 | |||
1613 | case SNDCTL_DSP_GETISPACE: | ||
1614 | if (!(file->f_mode & FMODE_READ)) | ||
1615 | return -EINVAL; | ||
1616 | abinfo.fragsize = s->dma_adc.fragsize; | ||
1617 | spin_lock_irqsave(&s->lock, flags); | ||
1618 | count = s->dma_adc.count; | ||
1619 | count += dma_count_done(&s->dma_adc); | ||
1620 | spin_unlock_irqrestore(&s->lock, flags); | ||
1621 | if (count < 0) | ||
1622 | count = 0; | ||
1623 | abinfo.bytes = count / s->dma_adc.cnt_factor; | ||
1624 | abinfo.fragstotal = s->dma_adc.numfrag; | ||
1625 | abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift; | ||
1626 | return copy_to_user((void *) arg, &abinfo, | ||
1627 | sizeof(abinfo)) ? -EFAULT : 0; | ||
1628 | |||
1629 | case SNDCTL_DSP_NONBLOCK: | ||
1630 | spin_lock(&file->f_lock); | ||
1631 | file->f_flags |= O_NONBLOCK; | ||
1632 | spin_unlock(&file->f_lock); | ||
1633 | return 0; | ||
1634 | |||
1635 | case SNDCTL_DSP_GETODELAY: | ||
1636 | if (!(file->f_mode & FMODE_WRITE)) | ||
1637 | return -EINVAL; | ||
1638 | spin_lock_irqsave(&s->lock, flags); | ||
1639 | count = s->dma_dac.count; | ||
1640 | count -= dma_count_done(&s->dma_dac); | ||
1641 | spin_unlock_irqrestore(&s->lock, flags); | ||
1642 | if (count < 0) | ||
1643 | count = 0; | ||
1644 | count /= s->dma_dac.cnt_factor; | ||
1645 | return put_user(count, (int *) arg); | ||
1646 | |||
1647 | case SNDCTL_DSP_GETIPTR: | ||
1648 | if (!(file->f_mode & FMODE_READ)) | ||
1649 | return -EINVAL; | ||
1650 | spin_lock_irqsave(&s->lock, flags); | ||
1651 | cinfo.bytes = s->dma_adc.total_bytes; | ||
1652 | count = s->dma_adc.count; | ||
1653 | if (!s->dma_adc.stopped) { | ||
1654 | diff = dma_count_done(&s->dma_adc); | ||
1655 | count += diff; | ||
1656 | cinfo.bytes += diff; | ||
1657 | cinfo.ptr = virt_to_phys(s->dma_adc.nextIn) + diff - | ||
1658 | virt_to_phys(s->dma_adc.rawbuf); | ||
1659 | } else | ||
1660 | cinfo.ptr = virt_to_phys(s->dma_adc.nextIn) - | ||
1661 | virt_to_phys(s->dma_adc.rawbuf); | ||
1662 | if (s->dma_adc.mapped) | ||
1663 | s->dma_adc.count &= (s->dma_adc.dma_fragsize-1); | ||
1664 | spin_unlock_irqrestore(&s->lock, flags); | ||
1665 | if (count < 0) | ||
1666 | count = 0; | ||
1667 | cinfo.blocks = count >> s->dma_adc.fragshift; | ||
1668 | return copy_to_user((void *) arg, &cinfo, sizeof(cinfo)); | ||
1669 | |||
1670 | case SNDCTL_DSP_GETOPTR: | ||
1671 | if (!(file->f_mode & FMODE_READ)) | ||
1672 | return -EINVAL; | ||
1673 | spin_lock_irqsave(&s->lock, flags); | ||
1674 | cinfo.bytes = s->dma_dac.total_bytes; | ||
1675 | count = s->dma_dac.count; | ||
1676 | if (!s->dma_dac.stopped) { | ||
1677 | diff = dma_count_done(&s->dma_dac); | ||
1678 | count -= diff; | ||
1679 | cinfo.bytes += diff; | ||
1680 | cinfo.ptr = virt_to_phys(s->dma_dac.nextOut) + diff - | ||
1681 | virt_to_phys(s->dma_dac.rawbuf); | ||
1682 | } else | ||
1683 | cinfo.ptr = virt_to_phys(s->dma_dac.nextOut) - | ||
1684 | virt_to_phys(s->dma_dac.rawbuf); | ||
1685 | if (s->dma_dac.mapped) | ||
1686 | s->dma_dac.count &= (s->dma_dac.dma_fragsize-1); | ||
1687 | spin_unlock_irqrestore(&s->lock, flags); | ||
1688 | if (count < 0) | ||
1689 | count = 0; | ||
1690 | cinfo.blocks = count >> s->dma_dac.fragshift; | ||
1691 | return copy_to_user((void *) arg, &cinfo, sizeof(cinfo)); | ||
1692 | |||
1693 | case SNDCTL_DSP_GETBLKSIZE: | ||
1694 | if (file->f_mode & FMODE_WRITE) | ||
1695 | return put_user(s->dma_dac.fragsize, (int *) arg); | ||
1696 | else | ||
1697 | return put_user(s->dma_adc.fragsize, (int *) arg); | ||
1698 | |||
1699 | case SNDCTL_DSP_SETFRAGMENT: | ||
1700 | if (get_user(val, (int *) arg)) | ||
1701 | return -EFAULT; | ||
1702 | if (file->f_mode & FMODE_READ) { | ||
1703 | stop_adc(s); | ||
1704 | s->dma_adc.ossfragshift = val & 0xffff; | ||
1705 | s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff; | ||
1706 | if (s->dma_adc.ossfragshift < 4) | ||
1707 | s->dma_adc.ossfragshift = 4; | ||
1708 | if (s->dma_adc.ossfragshift > 15) | ||
1709 | s->dma_adc.ossfragshift = 15; | ||
1710 | if (s->dma_adc.ossmaxfrags < 4) | ||
1711 | s->dma_adc.ossmaxfrags = 4; | ||
1712 | if ((ret = prog_dmabuf_adc(s))) | ||
1713 | return ret; | ||
1714 | } | ||
1715 | if (file->f_mode & FMODE_WRITE) { | ||
1716 | stop_dac(s); | ||
1717 | s->dma_dac.ossfragshift = val & 0xffff; | ||
1718 | s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff; | ||
1719 | if (s->dma_dac.ossfragshift < 4) | ||
1720 | s->dma_dac.ossfragshift = 4; | ||
1721 | if (s->dma_dac.ossfragshift > 15) | ||
1722 | s->dma_dac.ossfragshift = 15; | ||
1723 | if (s->dma_dac.ossmaxfrags < 4) | ||
1724 | s->dma_dac.ossmaxfrags = 4; | ||
1725 | if ((ret = prog_dmabuf_dac(s))) | ||
1726 | return ret; | ||
1727 | } | ||
1728 | return 0; | ||
1729 | |||
1730 | case SNDCTL_DSP_SUBDIVIDE: | ||
1731 | if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) || | ||
1732 | (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision)) | ||
1733 | return -EINVAL; | ||
1734 | if (get_user(val, (int *) arg)) | ||
1735 | return -EFAULT; | ||
1736 | if (val != 1 && val != 2 && val != 4) | ||
1737 | return -EINVAL; | ||
1738 | if (file->f_mode & FMODE_READ) { | ||
1739 | stop_adc(s); | ||
1740 | s->dma_adc.subdivision = val; | ||
1741 | if ((ret = prog_dmabuf_adc(s))) | ||
1742 | return ret; | ||
1743 | } | ||
1744 | if (file->f_mode & FMODE_WRITE) { | ||
1745 | stop_dac(s); | ||
1746 | s->dma_dac.subdivision = val; | ||
1747 | if ((ret = prog_dmabuf_dac(s))) | ||
1748 | return ret; | ||
1749 | } | ||
1750 | return 0; | ||
1751 | |||
1752 | case SOUND_PCM_READ_RATE: | ||
1753 | return put_user((file->f_mode & FMODE_READ) ? | ||
1754 | s->dma_adc.sample_rate : | ||
1755 | s->dma_dac.sample_rate, | ||
1756 | (int *)arg); | ||
1757 | |||
1758 | case SOUND_PCM_READ_CHANNELS: | ||
1759 | if (file->f_mode & FMODE_READ) | ||
1760 | return put_user(s->dma_adc.num_channels, (int *)arg); | ||
1761 | else | ||
1762 | return put_user(s->dma_dac.num_channels, (int *)arg); | ||
1763 | |||
1764 | case SOUND_PCM_READ_BITS: | ||
1765 | if (file->f_mode & FMODE_READ) | ||
1766 | return put_user(s->dma_adc.sample_size, (int *)arg); | ||
1767 | else | ||
1768 | return put_user(s->dma_dac.sample_size, (int *)arg); | ||
1769 | |||
1770 | case SOUND_PCM_WRITE_FILTER: | ||
1771 | case SNDCTL_DSP_SETSYNCRO: | ||
1772 | case SOUND_PCM_READ_FILTER: | ||
1773 | return -EINVAL; | ||
1774 | } | ||
1775 | |||
1776 | return mixdev_ioctl(s->codec, cmd, arg); | ||
1777 | } | ||
1778 | |||
1779 | static long | ||
1780 | au1550_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | ||
1781 | { | ||
1782 | int ret; | ||
1783 | |||
1784 | lock_kernel(); | ||
1785 | ret = au1550_ioctl(file, cmd, arg); | ||
1786 | unlock_kernel(); | ||
1787 | |||
1788 | return ret; | ||
1789 | } | ||
1790 | |||
1791 | static int | ||
1792 | au1550_open(struct inode *inode, struct file *file) | ||
1793 | { | ||
1794 | int minor = MINOR(inode->i_rdev); | ||
1795 | DECLARE_WAITQUEUE(wait, current); | ||
1796 | struct au1550_state *s = &au1550_state; | ||
1797 | int ret; | ||
1798 | |||
1799 | #ifdef DEBUG | ||
1800 | if (file->f_flags & O_NONBLOCK) | ||
1801 | pr_debug("open: non-blocking\n"); | ||
1802 | else | ||
1803 | pr_debug("open: blocking\n"); | ||
1804 | #endif | ||
1805 | |||
1806 | file->private_data = s; | ||
1807 | lock_kernel(); | ||
1808 | /* wait for device to become free */ | ||
1809 | mutex_lock(&s->open_mutex); | ||
1810 | while (s->open_mode & file->f_mode) { | ||
1811 | ret = -EBUSY; | ||
1812 | if (file->f_flags & O_NONBLOCK) | ||
1813 | goto out; | ||
1814 | add_wait_queue(&s->open_wait, &wait); | ||
1815 | __set_current_state(TASK_INTERRUPTIBLE); | ||
1816 | mutex_unlock(&s->open_mutex); | ||
1817 | schedule(); | ||
1818 | remove_wait_queue(&s->open_wait, &wait); | ||
1819 | set_current_state(TASK_RUNNING); | ||
1820 | ret = -ERESTARTSYS; | ||
1821 | if (signal_pending(current)) | ||
1822 | goto out2; | ||
1823 | mutex_lock(&s->open_mutex); | ||
1824 | } | ||
1825 | |||
1826 | stop_dac(s); | ||
1827 | stop_adc(s); | ||
1828 | |||
1829 | if (file->f_mode & FMODE_READ) { | ||
1830 | s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags = | ||
1831 | s->dma_adc.subdivision = s->dma_adc.total_bytes = 0; | ||
1832 | s->dma_adc.num_channels = 1; | ||
1833 | s->dma_adc.sample_size = 8; | ||
1834 | set_adc_rate(s, 8000); | ||
1835 | if ((minor & 0xf) == SND_DEV_DSP16) | ||
1836 | s->dma_adc.sample_size = 16; | ||
1837 | } | ||
1838 | |||
1839 | if (file->f_mode & FMODE_WRITE) { | ||
1840 | s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags = | ||
1841 | s->dma_dac.subdivision = s->dma_dac.total_bytes = 0; | ||
1842 | s->dma_dac.num_channels = 1; | ||
1843 | s->dma_dac.sample_size = 8; | ||
1844 | set_dac_rate(s, 8000); | ||
1845 | if ((minor & 0xf) == SND_DEV_DSP16) | ||
1846 | s->dma_dac.sample_size = 16; | ||
1847 | } | ||
1848 | |||
1849 | if (file->f_mode & FMODE_READ) { | ||
1850 | if ((ret = prog_dmabuf_adc(s))) | ||
1851 | goto out; | ||
1852 | } | ||
1853 | if (file->f_mode & FMODE_WRITE) { | ||
1854 | if ((ret = prog_dmabuf_dac(s))) | ||
1855 | goto out; | ||
1856 | } | ||
1857 | |||
1858 | s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE); | ||
1859 | mutex_init(&s->sem); | ||
1860 | ret = 0; | ||
1861 | out: | ||
1862 | mutex_unlock(&s->open_mutex); | ||
1863 | out2: | ||
1864 | unlock_kernel(); | ||
1865 | return ret; | ||
1866 | } | ||
1867 | |||
1868 | static int | ||
1869 | au1550_release(struct inode *inode, struct file *file) | ||
1870 | { | ||
1871 | struct au1550_state *s = (struct au1550_state *)file->private_data; | ||
1872 | |||
1873 | lock_kernel(); | ||
1874 | |||
1875 | if (file->f_mode & FMODE_WRITE) { | ||
1876 | unlock_kernel(); | ||
1877 | drain_dac(s, file->f_flags & O_NONBLOCK); | ||
1878 | lock_kernel(); | ||
1879 | } | ||
1880 | |||
1881 | mutex_lock(&s->open_mutex); | ||
1882 | if (file->f_mode & FMODE_WRITE) { | ||
1883 | stop_dac(s); | ||
1884 | kfree(s->dma_dac.rawbuf); | ||
1885 | s->dma_dac.rawbuf = NULL; | ||
1886 | } | ||
1887 | if (file->f_mode & FMODE_READ) { | ||
1888 | stop_adc(s); | ||
1889 | kfree(s->dma_adc.rawbuf); | ||
1890 | s->dma_adc.rawbuf = NULL; | ||
1891 | } | ||
1892 | s->open_mode &= ((~file->f_mode) & (FMODE_READ|FMODE_WRITE)); | ||
1893 | mutex_unlock(&s->open_mutex); | ||
1894 | wake_up(&s->open_wait); | ||
1895 | unlock_kernel(); | ||
1896 | return 0; | ||
1897 | } | ||
1898 | |||
1899 | static /*const */ struct file_operations au1550_audio_fops = { | ||
1900 | .owner = THIS_MODULE, | ||
1901 | .llseek = au1550_llseek, | ||
1902 | .read = au1550_read, | ||
1903 | .write = au1550_write, | ||
1904 | .poll = au1550_poll, | ||
1905 | .unlocked_ioctl = au1550_unlocked_ioctl, | ||
1906 | .mmap = au1550_mmap, | ||
1907 | .open = au1550_open, | ||
1908 | .release = au1550_release, | ||
1909 | }; | ||
1910 | |||
1911 | MODULE_AUTHOR("Advanced Micro Devices (AMD), dan@embeddededge.com"); | ||
1912 | MODULE_DESCRIPTION("Au1550 AC97 Audio Driver"); | ||
1913 | MODULE_LICENSE("GPL"); | ||
1914 | |||
1915 | |||
1916 | static int __devinit | ||
1917 | au1550_probe(void) | ||
1918 | { | ||
1919 | struct au1550_state *s = &au1550_state; | ||
1920 | int val; | ||
1921 | |||
1922 | memset(s, 0, sizeof(struct au1550_state)); | ||
1923 | |||
1924 | init_waitqueue_head(&s->dma_adc.wait); | ||
1925 | init_waitqueue_head(&s->dma_dac.wait); | ||
1926 | init_waitqueue_head(&s->open_wait); | ||
1927 | mutex_init(&s->open_mutex); | ||
1928 | spin_lock_init(&s->lock); | ||
1929 | |||
1930 | s->codec = ac97_alloc_codec(); | ||
1931 | if(s->codec == NULL) { | ||
1932 | err("Out of memory"); | ||
1933 | return -1; | ||
1934 | } | ||
1935 | s->codec->private_data = s; | ||
1936 | s->codec->id = 0; | ||
1937 | s->codec->codec_read = rdcodec; | ||
1938 | s->codec->codec_write = wrcodec; | ||
1939 | s->codec->codec_wait = waitcodec; | ||
1940 | |||
1941 | if (!request_mem_region(CPHYSADDR(AC97_PSC_SEL), | ||
1942 | 0x30, "Au1550 AC97")) { | ||
1943 | err("AC'97 ports in use"); | ||
1944 | } | ||
1945 | |||
1946 | /* Allocate the DMA Channels | ||
1947 | */ | ||
1948 | if ((s->dma_dac.dmanr = au1xxx_dbdma_chan_alloc(DBDMA_MEM_CHAN, | ||
1949 | DBDMA_AC97_TX_CHAN, dac_dma_interrupt, (void *)s)) == 0) { | ||
1950 | err("Can't get DAC DMA"); | ||
1951 | goto err_dma1; | ||
1952 | } | ||
1953 | au1xxx_dbdma_set_devwidth(s->dma_dac.dmanr, 16); | ||
1954 | if (au1xxx_dbdma_ring_alloc(s->dma_dac.dmanr, | ||
1955 | NUM_DBDMA_DESCRIPTORS) == 0) { | ||
1956 | err("Can't get DAC DMA descriptors"); | ||
1957 | goto err_dma1; | ||
1958 | } | ||
1959 | |||
1960 | if ((s->dma_adc.dmanr = au1xxx_dbdma_chan_alloc(DBDMA_AC97_RX_CHAN, | ||
1961 | DBDMA_MEM_CHAN, adc_dma_interrupt, (void *)s)) == 0) { | ||
1962 | err("Can't get ADC DMA"); | ||
1963 | goto err_dma2; | ||
1964 | } | ||
1965 | au1xxx_dbdma_set_devwidth(s->dma_adc.dmanr, 16); | ||
1966 | if (au1xxx_dbdma_ring_alloc(s->dma_adc.dmanr, | ||
1967 | NUM_DBDMA_DESCRIPTORS) == 0) { | ||
1968 | err("Can't get ADC DMA descriptors"); | ||
1969 | goto err_dma2; | ||
1970 | } | ||
1971 | |||
1972 | pr_info("DAC: DMA%d, ADC: DMA%d", DBDMA_AC97_TX_CHAN, DBDMA_AC97_RX_CHAN); | ||
1973 | |||
1974 | /* register devices */ | ||
1975 | |||
1976 | if ((s->dev_audio = register_sound_dsp(&au1550_audio_fops, -1)) < 0) | ||
1977 | goto err_dev1; | ||
1978 | if ((s->codec->dev_mixer = | ||
1979 | register_sound_mixer(&au1550_mixer_fops, -1)) < 0) | ||
1980 | goto err_dev2; | ||
1981 | |||
1982 | /* The GPIO for the appropriate PSC was configured by the | ||
1983 | * board specific start up. | ||
1984 | * | ||
1985 | * configure PSC for AC'97 | ||
1986 | */ | ||
1987 | au_writel(0, AC97_PSC_CTRL); /* Disable PSC */ | ||
1988 | au_sync(); | ||
1989 | au_writel((PSC_SEL_CLK_SERCLK | PSC_SEL_PS_AC97MODE), AC97_PSC_SEL); | ||
1990 | au_sync(); | ||
1991 | |||
1992 | /* cold reset the AC'97 | ||
1993 | */ | ||
1994 | au_writel(PSC_AC97RST_RST, PSC_AC97RST); | ||
1995 | au_sync(); | ||
1996 | au1550_delay(10); | ||
1997 | au_writel(0, PSC_AC97RST); | ||
1998 | au_sync(); | ||
1999 | |||
2000 | /* need to delay around 500msec(bleech) to give | ||
2001 | some CODECs enough time to wakeup */ | ||
2002 | au1550_delay(500); | ||
2003 | |||
2004 | /* warm reset the AC'97 to start the bitclk | ||
2005 | */ | ||
2006 | au_writel(PSC_AC97RST_SNC, PSC_AC97RST); | ||
2007 | au_sync(); | ||
2008 | udelay(100); | ||
2009 | au_writel(0, PSC_AC97RST); | ||
2010 | au_sync(); | ||
2011 | |||
2012 | /* Enable PSC | ||
2013 | */ | ||
2014 | au_writel(PSC_CTRL_ENABLE, AC97_PSC_CTRL); | ||
2015 | au_sync(); | ||
2016 | |||
2017 | /* Wait for PSC ready. | ||
2018 | */ | ||
2019 | do { | ||
2020 | val = au_readl(PSC_AC97STAT); | ||
2021 | au_sync(); | ||
2022 | } while ((val & PSC_AC97STAT_SR) == 0); | ||
2023 | |||
2024 | /* Configure AC97 controller. | ||
2025 | * Deep FIFO, 16-bit sample, DMA, make sure DMA matches fifo size. | ||
2026 | */ | ||
2027 | val = PSC_AC97CFG_SET_LEN(16); | ||
2028 | val |= PSC_AC97CFG_RT_FIFO8 | PSC_AC97CFG_TT_FIFO8; | ||
2029 | |||
2030 | /* Enable device so we can at least | ||
2031 | * talk over the AC-link. | ||
2032 | */ | ||
2033 | au_writel(val, PSC_AC97CFG); | ||
2034 | au_writel(PSC_AC97MSK_ALLMASK, PSC_AC97MSK); | ||
2035 | au_sync(); | ||
2036 | val |= PSC_AC97CFG_DE_ENABLE; | ||
2037 | au_writel(val, PSC_AC97CFG); | ||
2038 | au_sync(); | ||
2039 | |||
2040 | /* Wait for Device ready. | ||
2041 | */ | ||
2042 | do { | ||
2043 | val = au_readl(PSC_AC97STAT); | ||
2044 | au_sync(); | ||
2045 | } while ((val & PSC_AC97STAT_DR) == 0); | ||
2046 | |||
2047 | /* codec init */ | ||
2048 | if (!ac97_probe_codec(s->codec)) | ||
2049 | goto err_dev3; | ||
2050 | |||
2051 | s->codec_base_caps = rdcodec(s->codec, AC97_RESET); | ||
2052 | s->codec_ext_caps = rdcodec(s->codec, AC97_EXTENDED_ID); | ||
2053 | pr_info("AC'97 Base/Extended ID = %04x/%04x", | ||
2054 | s->codec_base_caps, s->codec_ext_caps); | ||
2055 | |||
2056 | if (!(s->codec_ext_caps & AC97_EXTID_VRA)) { | ||
2057 | /* codec does not support VRA | ||
2058 | */ | ||
2059 | s->no_vra = 1; | ||
2060 | } else if (!vra) { | ||
2061 | /* Boot option says disable VRA | ||
2062 | */ | ||
2063 | u16 ac97_extstat = rdcodec(s->codec, AC97_EXTENDED_STATUS); | ||
2064 | wrcodec(s->codec, AC97_EXTENDED_STATUS, | ||
2065 | ac97_extstat & ~AC97_EXTSTAT_VRA); | ||
2066 | s->no_vra = 1; | ||
2067 | } | ||
2068 | if (s->no_vra) | ||
2069 | pr_info("no VRA, interpolating and decimating"); | ||
2070 | |||
2071 | /* set mic to be the recording source */ | ||
2072 | val = SOUND_MASK_MIC; | ||
2073 | mixdev_ioctl(s->codec, SOUND_MIXER_WRITE_RECSRC, | ||
2074 | (unsigned long) &val); | ||
2075 | |||
2076 | return 0; | ||
2077 | |||
2078 | err_dev3: | ||
2079 | unregister_sound_mixer(s->codec->dev_mixer); | ||
2080 | err_dev2: | ||
2081 | unregister_sound_dsp(s->dev_audio); | ||
2082 | err_dev1: | ||
2083 | au1xxx_dbdma_chan_free(s->dma_adc.dmanr); | ||
2084 | err_dma2: | ||
2085 | au1xxx_dbdma_chan_free(s->dma_dac.dmanr); | ||
2086 | err_dma1: | ||
2087 | release_mem_region(CPHYSADDR(AC97_PSC_SEL), 0x30); | ||
2088 | |||
2089 | ac97_release_codec(s->codec); | ||
2090 | return -1; | ||
2091 | } | ||
2092 | |||
2093 | static void __devinit | ||
2094 | au1550_remove(void) | ||
2095 | { | ||
2096 | struct au1550_state *s = &au1550_state; | ||
2097 | |||
2098 | if (!s) | ||
2099 | return; | ||
2100 | synchronize_irq(); | ||
2101 | au1xxx_dbdma_chan_free(s->dma_adc.dmanr); | ||
2102 | au1xxx_dbdma_chan_free(s->dma_dac.dmanr); | ||
2103 | release_mem_region(CPHYSADDR(AC97_PSC_SEL), 0x30); | ||
2104 | unregister_sound_dsp(s->dev_audio); | ||
2105 | unregister_sound_mixer(s->codec->dev_mixer); | ||
2106 | ac97_release_codec(s->codec); | ||
2107 | } | ||
2108 | |||
2109 | static int __init | ||
2110 | init_au1550(void) | ||
2111 | { | ||
2112 | return au1550_probe(); | ||
2113 | } | ||
2114 | |||
2115 | static void __exit | ||
2116 | cleanup_au1550(void) | ||
2117 | { | ||
2118 | au1550_remove(); | ||
2119 | } | ||
2120 | |||
2121 | module_init(init_au1550); | ||
2122 | module_exit(cleanup_au1550); | ||
2123 | |||
2124 | #ifndef MODULE | ||
2125 | |||
2126 | static int __init | ||
2127 | au1550_setup(char *options) | ||
2128 | { | ||
2129 | char *this_opt; | ||
2130 | |||
2131 | if (!options || !*options) | ||
2132 | return 0; | ||
2133 | |||
2134 | while ((this_opt = strsep(&options, ","))) { | ||
2135 | if (!*this_opt) | ||
2136 | continue; | ||
2137 | if (!strncmp(this_opt, "vra", 3)) { | ||
2138 | vra = 1; | ||
2139 | } | ||
2140 | } | ||
2141 | |||
2142 | return 1; | ||
2143 | } | ||
2144 | |||
2145 | __setup("au1550_audio=", au1550_setup); | ||
2146 | |||
2147 | #endif /* MODULE */ | ||
diff --git a/sound/oss/audio.c b/sound/oss/audio.c index 7df48a25c4ee..4b958b1c497c 100644 --- a/sound/oss/audio.c +++ b/sound/oss/audio.c | |||
@@ -514,7 +514,7 @@ int audio_ioctl(int dev, struct file *file, unsigned int cmd, void __user *arg) | |||
514 | count += dmap->bytes_in_use; /* Pointer wrap not handled yet */ | 514 | count += dmap->bytes_in_use; /* Pointer wrap not handled yet */ |
515 | count += dmap->byte_counter; | 515 | count += dmap->byte_counter; |
516 | 516 | ||
517 | /* Substract current count from the number of bytes written by app */ | 517 | /* Subtract current count from the number of bytes written by app */ |
518 | count = dmap->user_counter - count; | 518 | count = dmap->user_counter - count; |
519 | if (count < 0) | 519 | if (count < 0) |
520 | count = 0; | 520 | count = 0; |
@@ -931,7 +931,7 @@ static int dma_ioctl(int dev, unsigned int cmd, void __user *arg) | |||
931 | if (count < dmap_out->fragment_size && dmap_out->qhead != 0) | 931 | if (count < dmap_out->fragment_size && dmap_out->qhead != 0) |
932 | count += dmap_out->bytes_in_use; /* Pointer wrap not handled yet */ | 932 | count += dmap_out->bytes_in_use; /* Pointer wrap not handled yet */ |
933 | count += dmap_out->byte_counter; | 933 | count += dmap_out->byte_counter; |
934 | /* Substract current count from the number of bytes written by app */ | 934 | /* Subtract current count from the number of bytes written by app */ |
935 | count = dmap_out->user_counter - count; | 935 | count = dmap_out->user_counter - count; |
936 | if (count < 0) | 936 | if (count < 0) |
937 | count = 0; | 937 | count = 0; |
diff --git a/sound/oss/dev_table.c b/sound/oss/dev_table.c index 727bdb9ba2dc..d8cf3e58dc76 100644 --- a/sound/oss/dev_table.c +++ b/sound/oss/dev_table.c | |||
@@ -71,7 +71,7 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver, | |||
71 | if (sound_nblocks >= MAX_MEM_BLOCKS) | 71 | if (sound_nblocks >= MAX_MEM_BLOCKS) |
72 | sound_nblocks = MAX_MEM_BLOCKS - 1; | 72 | sound_nblocks = MAX_MEM_BLOCKS - 1; |
73 | 73 | ||
74 | op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_operations))); | 74 | op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vzalloc(sizeof(struct audio_operations))); |
75 | sound_nblocks++; | 75 | sound_nblocks++; |
76 | if (sound_nblocks >= MAX_MEM_BLOCKS) | 76 | if (sound_nblocks >= MAX_MEM_BLOCKS) |
77 | sound_nblocks = MAX_MEM_BLOCKS - 1; | 77 | sound_nblocks = MAX_MEM_BLOCKS - 1; |
@@ -81,7 +81,6 @@ int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver, | |||
81 | sound_unload_audiodev(num); | 81 | sound_unload_audiodev(num); |
82 | return -(ENOMEM); | 82 | return -(ENOMEM); |
83 | } | 83 | } |
84 | memset((char *) op, 0, sizeof(struct audio_operations)); | ||
85 | init_waitqueue_head(&op->in_sleeper); | 84 | init_waitqueue_head(&op->in_sleeper); |
86 | init_waitqueue_head(&op->out_sleeper); | 85 | init_waitqueue_head(&op->out_sleeper); |
87 | init_waitqueue_head(&op->poll_sleeper); | 86 | init_waitqueue_head(&op->poll_sleeper); |
@@ -128,7 +127,7 @@ int sound_install_mixer(int vers, char *name, struct mixer_operations *driver, | |||
128 | /* FIXME: This leaks a mixer_operations struct every time its called | 127 | /* FIXME: This leaks a mixer_operations struct every time its called |
129 | until you unload sound! */ | 128 | until you unload sound! */ |
130 | 129 | ||
131 | op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct mixer_operations))); | 130 | op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vzalloc(sizeof(struct mixer_operations))); |
132 | sound_nblocks++; | 131 | sound_nblocks++; |
133 | if (sound_nblocks >= MAX_MEM_BLOCKS) | 132 | if (sound_nblocks >= MAX_MEM_BLOCKS) |
134 | sound_nblocks = MAX_MEM_BLOCKS - 1; | 133 | sound_nblocks = MAX_MEM_BLOCKS - 1; |
@@ -137,7 +136,6 @@ int sound_install_mixer(int vers, char *name, struct mixer_operations *driver, | |||
137 | printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name); | 136 | printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name); |
138 | return -ENOMEM; | 137 | return -ENOMEM; |
139 | } | 138 | } |
140 | memset((char *) op, 0, sizeof(struct mixer_operations)); | ||
141 | memcpy((char *) op, (char *) driver, driver_size); | 139 | memcpy((char *) op, (char *) driver, driver_size); |
142 | 140 | ||
143 | strlcpy(op->name, name, sizeof(op->name)); | 141 | strlcpy(op->name, name, sizeof(op->name)); |
diff --git a/sound/oss/dev_table.h b/sound/oss/dev_table.h index b7617bee6388..0199a317c5a9 100644 --- a/sound/oss/dev_table.h +++ b/sound/oss/dev_table.h | |||
@@ -271,7 +271,7 @@ struct synth_operations | |||
271 | void (*reset) (int dev); | 271 | void (*reset) (int dev); |
272 | void (*hw_control) (int dev, unsigned char *event); | 272 | void (*hw_control) (int dev, unsigned char *event); |
273 | int (*load_patch) (int dev, int format, const char __user *addr, | 273 | int (*load_patch) (int dev, int format, const char __user *addr, |
274 | int offs, int count, int pmgr_flag); | 274 | int count, int pmgr_flag); |
275 | void (*aftertouch) (int dev, int voice, int pressure); | 275 | void (*aftertouch) (int dev, int voice, int pressure); |
276 | void (*controller) (int dev, int voice, int ctrl_num, int value); | 276 | void (*controller) (int dev, int voice, int ctrl_num, int value); |
277 | void (*panning) (int dev, int voice, int value); | 277 | void (*panning) (int dev, int voice, int value); |
diff --git a/sound/oss/dmasound/dmasound_core.c b/sound/oss/dmasound/dmasound_core.c index 6ecd41abb066..c918313c2206 100644 --- a/sound/oss/dmasound/dmasound_core.c +++ b/sound/oss/dmasound/dmasound_core.c | |||
@@ -181,7 +181,7 @@ | |||
181 | #include <linux/init.h> | 181 | #include <linux/init.h> |
182 | #include <linux/soundcard.h> | 182 | #include <linux/soundcard.h> |
183 | #include <linux/poll.h> | 183 | #include <linux/poll.h> |
184 | #include <linux/smp_lock.h> | 184 | #include <linux/mutex.h> |
185 | 185 | ||
186 | #include <asm/uaccess.h> | 186 | #include <asm/uaccess.h> |
187 | 187 | ||
@@ -194,6 +194,7 @@ | |||
194 | * Declarations | 194 | * Declarations |
195 | */ | 195 | */ |
196 | 196 | ||
197 | static DEFINE_MUTEX(dmasound_core_mutex); | ||
197 | int dmasound_catchRadius = 0; | 198 | int dmasound_catchRadius = 0; |
198 | module_param(dmasound_catchRadius, int, 0); | 199 | module_param(dmasound_catchRadius, int, 0); |
199 | 200 | ||
@@ -323,22 +324,22 @@ static struct { | |||
323 | 324 | ||
324 | static int mixer_open(struct inode *inode, struct file *file) | 325 | static int mixer_open(struct inode *inode, struct file *file) |
325 | { | 326 | { |
326 | lock_kernel(); | 327 | mutex_lock(&dmasound_core_mutex); |
327 | if (!try_module_get(dmasound.mach.owner)) { | 328 | if (!try_module_get(dmasound.mach.owner)) { |
328 | unlock_kernel(); | 329 | mutex_unlock(&dmasound_core_mutex); |
329 | return -ENODEV; | 330 | return -ENODEV; |
330 | } | 331 | } |
331 | mixer.busy = 1; | 332 | mixer.busy = 1; |
332 | unlock_kernel(); | 333 | mutex_unlock(&dmasound_core_mutex); |
333 | return 0; | 334 | return 0; |
334 | } | 335 | } |
335 | 336 | ||
336 | static int mixer_release(struct inode *inode, struct file *file) | 337 | static int mixer_release(struct inode *inode, struct file *file) |
337 | { | 338 | { |
338 | lock_kernel(); | 339 | mutex_lock(&dmasound_core_mutex); |
339 | mixer.busy = 0; | 340 | mixer.busy = 0; |
340 | module_put(dmasound.mach.owner); | 341 | module_put(dmasound.mach.owner); |
341 | unlock_kernel(); | 342 | mutex_unlock(&dmasound_core_mutex); |
342 | return 0; | 343 | return 0; |
343 | } | 344 | } |
344 | 345 | ||
@@ -370,9 +371,9 @@ static long mixer_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) | |||
370 | { | 371 | { |
371 | int ret; | 372 | int ret; |
372 | 373 | ||
373 | lock_kernel(); | 374 | mutex_lock(&dmasound_core_mutex); |
374 | ret = mixer_ioctl(file, cmd, arg); | 375 | ret = mixer_ioctl(file, cmd, arg); |
375 | unlock_kernel(); | 376 | mutex_unlock(&dmasound_core_mutex); |
376 | 377 | ||
377 | return ret; | 378 | return ret; |
378 | } | 379 | } |
@@ -752,9 +753,9 @@ static int sq_open(struct inode *inode, struct file *file) | |||
752 | { | 753 | { |
753 | int rc; | 754 | int rc; |
754 | 755 | ||
755 | lock_kernel(); | 756 | mutex_lock(&dmasound_core_mutex); |
756 | if (!try_module_get(dmasound.mach.owner)) { | 757 | if (!try_module_get(dmasound.mach.owner)) { |
757 | unlock_kernel(); | 758 | mutex_unlock(&dmasound_core_mutex); |
758 | return -ENODEV; | 759 | return -ENODEV; |
759 | } | 760 | } |
760 | 761 | ||
@@ -799,11 +800,11 @@ static int sq_open(struct inode *inode, struct file *file) | |||
799 | sound_set_format(AFMT_MU_LAW); | 800 | sound_set_format(AFMT_MU_LAW); |
800 | } | 801 | } |
801 | #endif | 802 | #endif |
802 | unlock_kernel(); | 803 | mutex_unlock(&dmasound_core_mutex); |
803 | return 0; | 804 | return 0; |
804 | out: | 805 | out: |
805 | module_put(dmasound.mach.owner); | 806 | module_put(dmasound.mach.owner); |
806 | unlock_kernel(); | 807 | mutex_unlock(&dmasound_core_mutex); |
807 | return rc; | 808 | return rc; |
808 | } | 809 | } |
809 | 810 | ||
@@ -869,7 +870,7 @@ static int sq_release(struct inode *inode, struct file *file) | |||
869 | { | 870 | { |
870 | int rc = 0; | 871 | int rc = 0; |
871 | 872 | ||
872 | lock_kernel(); | 873 | mutex_lock(&dmasound_core_mutex); |
873 | 874 | ||
874 | if (file->f_mode & FMODE_WRITE) { | 875 | if (file->f_mode & FMODE_WRITE) { |
875 | if (write_sq.busy) | 876 | if (write_sq.busy) |
@@ -900,7 +901,7 @@ static int sq_release(struct inode *inode, struct file *file) | |||
900 | write_sq_wake_up(file); /* checks f_mode */ | 901 | write_sq_wake_up(file); /* checks f_mode */ |
901 | #endif /* blocking open() */ | 902 | #endif /* blocking open() */ |
902 | 903 | ||
903 | unlock_kernel(); | 904 | mutex_unlock(&dmasound_core_mutex); |
904 | 905 | ||
905 | return rc; | 906 | return rc; |
906 | } | 907 | } |
@@ -1020,7 +1021,7 @@ static int sq_ioctl(struct file *file, u_int cmd, u_long arg) | |||
1020 | case SNDCTL_DSP_SYNC: | 1021 | case SNDCTL_DSP_SYNC: |
1021 | /* This call, effectively, has the same behaviour as SNDCTL_DSP_RESET | 1022 | /* This call, effectively, has the same behaviour as SNDCTL_DSP_RESET |
1022 | except that it waits for output to finish before resetting | 1023 | except that it waits for output to finish before resetting |
1023 | everything - read, however, is killed imediately. | 1024 | everything - read, however, is killed immediately. |
1024 | */ | 1025 | */ |
1025 | result = 0 ; | 1026 | result = 0 ; |
1026 | if (file->f_mode & FMODE_WRITE) { | 1027 | if (file->f_mode & FMODE_WRITE) { |
@@ -1141,9 +1142,9 @@ static long sq_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) | |||
1141 | { | 1142 | { |
1142 | int ret; | 1143 | int ret; |
1143 | 1144 | ||
1144 | lock_kernel(); | 1145 | mutex_lock(&dmasound_core_mutex); |
1145 | ret = sq_ioctl(file, cmd, arg); | 1146 | ret = sq_ioctl(file, cmd, arg); |
1146 | unlock_kernel(); | 1147 | mutex_unlock(&dmasound_core_mutex); |
1147 | 1148 | ||
1148 | return ret; | 1149 | return ret; |
1149 | } | 1150 | } |
@@ -1257,7 +1258,7 @@ static int state_open(struct inode *inode, struct file *file) | |||
1257 | int len = 0; | 1258 | int len = 0; |
1258 | int ret; | 1259 | int ret; |
1259 | 1260 | ||
1260 | lock_kernel(); | 1261 | mutex_lock(&dmasound_core_mutex); |
1261 | ret = -EBUSY; | 1262 | ret = -EBUSY; |
1262 | if (state.busy) | 1263 | if (state.busy) |
1263 | goto out; | 1264 | goto out; |
@@ -1329,16 +1330,16 @@ printk("dmasound: stat buffer used %d bytes\n", len) ; | |||
1329 | state.len = len; | 1330 | state.len = len; |
1330 | ret = 0; | 1331 | ret = 0; |
1331 | out: | 1332 | out: |
1332 | unlock_kernel(); | 1333 | mutex_unlock(&dmasound_core_mutex); |
1333 | return ret; | 1334 | return ret; |
1334 | } | 1335 | } |
1335 | 1336 | ||
1336 | static int state_release(struct inode *inode, struct file *file) | 1337 | static int state_release(struct inode *inode, struct file *file) |
1337 | { | 1338 | { |
1338 | lock_kernel(); | 1339 | mutex_lock(&dmasound_core_mutex); |
1339 | state.busy = 0; | 1340 | state.busy = 0; |
1340 | module_put(dmasound.mach.owner); | 1341 | module_put(dmasound.mach.owner); |
1341 | unlock_kernel(); | 1342 | mutex_unlock(&dmasound_core_mutex); |
1342 | return 0; | 1343 | return 0; |
1343 | } | 1344 | } |
1344 | 1345 | ||
diff --git a/sound/oss/midi_synth.c b/sound/oss/midi_synth.c index 3c09374ea5bf..2292c230d7e6 100644 --- a/sound/oss/midi_synth.c +++ b/sound/oss/midi_synth.c | |||
@@ -476,7 +476,7 @@ EXPORT_SYMBOL(midi_synth_hw_control); | |||
476 | 476 | ||
477 | int | 477 | int |
478 | midi_synth_load_patch(int dev, int format, const char __user *addr, | 478 | midi_synth_load_patch(int dev, int format, const char __user *addr, |
479 | int offs, int count, int pmgr_flag) | 479 | int count, int pmgr_flag) |
480 | { | 480 | { |
481 | int orig_dev = synth_devs[dev]->midi_dev; | 481 | int orig_dev = synth_devs[dev]->midi_dev; |
482 | 482 | ||
@@ -491,33 +491,29 @@ midi_synth_load_patch(int dev, int format, const char __user *addr, | |||
491 | if (!prefix_cmd(orig_dev, 0xf0)) | 491 | if (!prefix_cmd(orig_dev, 0xf0)) |
492 | return 0; | 492 | return 0; |
493 | 493 | ||
494 | /* Invalid patch format */ | ||
494 | if (format != SYSEX_PATCH) | 495 | if (format != SYSEX_PATCH) |
495 | { | ||
496 | /* printk("MIDI Error: Invalid patch format (key) 0x%x\n", format);*/ | ||
497 | return -EINVAL; | 496 | return -EINVAL; |
498 | } | 497 | |
498 | /* Patch header too short */ | ||
499 | if (count < hdr_size) | 499 | if (count < hdr_size) |
500 | { | ||
501 | /* printk("MIDI Error: Patch header too short\n");*/ | ||
502 | return -EINVAL; | 500 | return -EINVAL; |
503 | } | 501 | |
504 | count -= hdr_size; | 502 | count -= hdr_size; |
505 | 503 | ||
506 | /* | 504 | /* |
507 | * Copy the header from user space but ignore the first bytes which have | 505 | * Copy the header from user space |
508 | * been transferred already. | ||
509 | */ | 506 | */ |
510 | 507 | ||
511 | if(copy_from_user(&((char *) &sysex)[offs], &(addr)[offs], hdr_size - offs)) | 508 | if (copy_from_user(&sysex, addr, hdr_size)) |
512 | return -EFAULT; | 509 | return -EFAULT; |
513 | 510 | ||
514 | if (count < sysex.len) | 511 | /* Sysex record too short */ |
515 | { | 512 | if ((unsigned)count < (unsigned)sysex.len) |
516 | /* printk(KERN_WARNING "MIDI Warning: Sysex record too short (%d<%d)\n", count, (int) sysex.len);*/ | ||
517 | sysex.len = count; | 513 | sysex.len = count; |
518 | } | 514 | |
519 | left = sysex.len; | 515 | left = sysex.len; |
520 | src_offs = 0; | 516 | src_offs = 0; |
521 | 517 | ||
522 | for (i = 0; i < left && !signal_pending(current); i++) | 518 | for (i = 0; i < left && !signal_pending(current); i++) |
523 | { | 519 | { |
diff --git a/sound/oss/midi_synth.h b/sound/oss/midi_synth.h index 6bc9d00bc77c..b64ddd6c4abc 100644 --- a/sound/oss/midi_synth.h +++ b/sound/oss/midi_synth.h | |||
@@ -8,7 +8,7 @@ int midi_synth_open (int dev, int mode); | |||
8 | void midi_synth_close (int dev); | 8 | void midi_synth_close (int dev); |
9 | void midi_synth_hw_control (int dev, unsigned char *event); | 9 | void midi_synth_hw_control (int dev, unsigned char *event); |
10 | int midi_synth_load_patch (int dev, int format, const char __user * addr, | 10 | int midi_synth_load_patch (int dev, int format, const char __user * addr, |
11 | int offs, int count, int pmgr_flag); | 11 | int count, int pmgr_flag); |
12 | void midi_synth_panning (int dev, int channel, int pressure); | 12 | void midi_synth_panning (int dev, int channel, int pressure); |
13 | void midi_synth_aftertouch (int dev, int channel, int pressure); | 13 | void midi_synth_aftertouch (int dev, int channel, int pressure); |
14 | void midi_synth_controller (int dev, int channel, int ctrl_num, int value); | 14 | void midi_synth_controller (int dev, int channel, int ctrl_num, int value); |
diff --git a/sound/oss/midibuf.c b/sound/oss/midibuf.c index 782b3b84dac6..8cdb2cfe65c8 100644 --- a/sound/oss/midibuf.c +++ b/sound/oss/midibuf.c | |||
@@ -178,7 +178,7 @@ int MIDIbuf_open(int dev, struct file *file) | |||
178 | return err; | 178 | return err; |
179 | 179 | ||
180 | parms[dev].prech_timeout = MAX_SCHEDULE_TIMEOUT; | 180 | parms[dev].prech_timeout = MAX_SCHEDULE_TIMEOUT; |
181 | midi_in_buf[dev] = (struct midi_buf *) vmalloc(sizeof(struct midi_buf)); | 181 | midi_in_buf[dev] = vmalloc(sizeof(struct midi_buf)); |
182 | 182 | ||
183 | if (midi_in_buf[dev] == NULL) | 183 | if (midi_in_buf[dev] == NULL) |
184 | { | 184 | { |
@@ -188,7 +188,7 @@ int MIDIbuf_open(int dev, struct file *file) | |||
188 | } | 188 | } |
189 | midi_in_buf[dev]->len = midi_in_buf[dev]->head = midi_in_buf[dev]->tail = 0; | 189 | midi_in_buf[dev]->len = midi_in_buf[dev]->head = midi_in_buf[dev]->tail = 0; |
190 | 190 | ||
191 | midi_out_buf[dev] = (struct midi_buf *) vmalloc(sizeof(struct midi_buf)); | 191 | midi_out_buf[dev] = vmalloc(sizeof(struct midi_buf)); |
192 | 192 | ||
193 | if (midi_out_buf[dev] == NULL) | 193 | if (midi_out_buf[dev] == NULL) |
194 | { | 194 | { |
@@ -295,7 +295,7 @@ int MIDIbuf_write(int dev, struct file *file, const char __user *buf, int count) | |||
295 | 295 | ||
296 | for (i = 0; i < n; i++) | 296 | for (i = 0; i < n; i++) |
297 | { | 297 | { |
298 | /* BROKE BROKE BROKE - CANT DO THIS WITH CLI !! */ | 298 | /* BROKE BROKE BROKE - CAN'T DO THIS WITH CLI !! */ |
299 | /* yes, think the same, so I removed the cli() brackets | 299 | /* yes, think the same, so I removed the cli() brackets |
300 | QUEUE_BYTE is protected against interrupts */ | 300 | QUEUE_BYTE is protected against interrupts */ |
301 | if (copy_from_user((char *) &tmp_data, &(buf)[c], 1)) { | 301 | if (copy_from_user((char *) &tmp_data, &(buf)[c], 1)) { |
diff --git a/sound/oss/msnd_pinnacle.c b/sound/oss/msnd_pinnacle.c index 2e48b17667d0..7b5c77b32a90 100644 --- a/sound/oss/msnd_pinnacle.c +++ b/sound/oss/msnd_pinnacle.c | |||
@@ -39,7 +39,7 @@ | |||
39 | #include <linux/delay.h> | 39 | #include <linux/delay.h> |
40 | #include <linux/init.h> | 40 | #include <linux/init.h> |
41 | #include <linux/interrupt.h> | 41 | #include <linux/interrupt.h> |
42 | #include <linux/smp_lock.h> | 42 | #include <linux/mutex.h> |
43 | #include <linux/gfp.h> | 43 | #include <linux/gfp.h> |
44 | #include <asm/irq.h> | 44 | #include <asm/irq.h> |
45 | #include <asm/io.h> | 45 | #include <asm/io.h> |
@@ -79,6 +79,7 @@ | |||
79 | dev.rec_sample_rate / \ | 79 | dev.rec_sample_rate / \ |
80 | dev.rec_channels) | 80 | dev.rec_channels) |
81 | 81 | ||
82 | static DEFINE_MUTEX(msnd_pinnacle_mutex); | ||
82 | static multisound_dev_t dev; | 83 | static multisound_dev_t dev; |
83 | 84 | ||
84 | #ifndef HAVE_DSPCODEH | 85 | #ifndef HAVE_DSPCODEH |
@@ -651,12 +652,12 @@ static long dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
651 | 652 | ||
652 | ret = -EINVAL; | 653 | ret = -EINVAL; |
653 | 654 | ||
654 | lock_kernel(); | 655 | mutex_lock(&msnd_pinnacle_mutex); |
655 | if (minor == dev.dsp_minor) | 656 | if (minor == dev.dsp_minor) |
656 | ret = dsp_ioctl(file, cmd, arg); | 657 | ret = dsp_ioctl(file, cmd, arg); |
657 | else if (minor == dev.mixer_minor) | 658 | else if (minor == dev.mixer_minor) |
658 | ret = mixer_ioctl(cmd, arg); | 659 | ret = mixer_ioctl(cmd, arg); |
659 | unlock_kernel(); | 660 | mutex_unlock(&msnd_pinnacle_mutex); |
660 | 661 | ||
661 | return ret; | 662 | return ret; |
662 | } | 663 | } |
@@ -761,7 +762,7 @@ static int dev_open(struct inode *inode, struct file *file) | |||
761 | int minor = iminor(inode); | 762 | int minor = iminor(inode); |
762 | int err = 0; | 763 | int err = 0; |
763 | 764 | ||
764 | lock_kernel(); | 765 | mutex_lock(&msnd_pinnacle_mutex); |
765 | if (minor == dev.dsp_minor) { | 766 | if (minor == dev.dsp_minor) { |
766 | if ((file->f_mode & FMODE_WRITE && | 767 | if ((file->f_mode & FMODE_WRITE && |
767 | test_bit(F_AUDIO_WRITE_INUSE, &dev.flags)) || | 768 | test_bit(F_AUDIO_WRITE_INUSE, &dev.flags)) || |
@@ -791,7 +792,7 @@ static int dev_open(struct inode *inode, struct file *file) | |||
791 | } else | 792 | } else |
792 | err = -EINVAL; | 793 | err = -EINVAL; |
793 | out: | 794 | out: |
794 | unlock_kernel(); | 795 | mutex_unlock(&msnd_pinnacle_mutex); |
795 | return err; | 796 | return err; |
796 | } | 797 | } |
797 | 798 | ||
@@ -800,14 +801,14 @@ static int dev_release(struct inode *inode, struct file *file) | |||
800 | int minor = iminor(inode); | 801 | int minor = iminor(inode); |
801 | int err = 0; | 802 | int err = 0; |
802 | 803 | ||
803 | lock_kernel(); | 804 | mutex_lock(&msnd_pinnacle_mutex); |
804 | if (minor == dev.dsp_minor) | 805 | if (minor == dev.dsp_minor) |
805 | err = dsp_release(file); | 806 | err = dsp_release(file); |
806 | else if (minor == dev.mixer_minor) { | 807 | else if (minor == dev.mixer_minor) { |
807 | /* nothing */ | 808 | /* nothing */ |
808 | } else | 809 | } else |
809 | err = -EINVAL; | 810 | err = -EINVAL; |
810 | unlock_kernel(); | 811 | mutex_unlock(&msnd_pinnacle_mutex); |
811 | return err; | 812 | return err; |
812 | } | 813 | } |
813 | 814 | ||
@@ -1117,6 +1118,7 @@ static const struct file_operations dev_fileops = { | |||
1117 | .unlocked_ioctl = dev_ioctl, | 1118 | .unlocked_ioctl = dev_ioctl, |
1118 | .open = dev_open, | 1119 | .open = dev_open, |
1119 | .release = dev_release, | 1120 | .release = dev_release, |
1121 | .llseek = noop_llseek, | ||
1120 | }; | 1122 | }; |
1121 | 1123 | ||
1122 | static int reset_dsp(void) | 1124 | static int reset_dsp(void) |
diff --git a/sound/oss/opl3.c b/sound/oss/opl3.c index 938c48c43585..407cd677950b 100644 --- a/sound/oss/opl3.c +++ b/sound/oss/opl3.c | |||
@@ -820,7 +820,7 @@ static void opl3_hw_control(int dev, unsigned char *event) | |||
820 | } | 820 | } |
821 | 821 | ||
822 | static int opl3_load_patch(int dev, int format, const char __user *addr, | 822 | static int opl3_load_patch(int dev, int format, const char __user *addr, |
823 | int offs, int count, int pmgr_flag) | 823 | int count, int pmgr_flag) |
824 | { | 824 | { |
825 | struct sbi_instrument ins; | 825 | struct sbi_instrument ins; |
826 | 826 | ||
@@ -830,11 +830,7 @@ static int opl3_load_patch(int dev, int format, const char __user *addr, | |||
830 | return -EINVAL; | 830 | return -EINVAL; |
831 | } | 831 | } |
832 | 832 | ||
833 | /* | 833 | if (copy_from_user(&ins, addr, sizeof(ins))) |
834 | * What the fuck is going on here? We leave junk in the beginning | ||
835 | * of ins and then check the field pretty close to that beginning? | ||
836 | */ | ||
837 | if(copy_from_user(&((char *) &ins)[offs], addr + offs, sizeof(ins) - offs)) | ||
838 | return -EFAULT; | 834 | return -EFAULT; |
839 | 835 | ||
840 | if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR) | 836 | if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR) |
@@ -849,6 +845,10 @@ static int opl3_load_patch(int dev, int format, const char __user *addr, | |||
849 | 845 | ||
850 | static void opl3_panning(int dev, int voice, int value) | 846 | static void opl3_panning(int dev, int voice, int value) |
851 | { | 847 | { |
848 | |||
849 | if (voice < 0 || voice >= devc->nr_voice) | ||
850 | return; | ||
851 | |||
852 | devc->voc[voice].panning = value; | 852 | devc->voc[voice].panning = value; |
853 | } | 853 | } |
854 | 854 | ||
@@ -1066,8 +1066,15 @@ static int opl3_alloc_voice(int dev, int chn, int note, struct voice_alloc_info | |||
1066 | 1066 | ||
1067 | static void opl3_setup_voice(int dev, int voice, int chn) | 1067 | static void opl3_setup_voice(int dev, int voice, int chn) |
1068 | { | 1068 | { |
1069 | struct channel_info *info = | 1069 | struct channel_info *info; |
1070 | &synth_devs[dev]->chn_info[chn]; | 1070 | |
1071 | if (voice < 0 || voice >= devc->nr_voice) | ||
1072 | return; | ||
1073 | |||
1074 | if (chn < 0 || chn > 15) | ||
1075 | return; | ||
1076 | |||
1077 | info = &synth_devs[dev]->chn_info[chn]; | ||
1071 | 1078 | ||
1072 | opl3_set_instr(dev, voice, info->pgm_num); | 1079 | opl3_set_instr(dev, voice, info->pgm_num); |
1073 | 1080 | ||
diff --git a/sound/oss/pss.c b/sound/oss/pss.c index e19dd5dcc2de..9b800ce5100e 100644 --- a/sound/oss/pss.c +++ b/sound/oss/pss.c | |||
@@ -859,7 +859,7 @@ static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, | |||
859 | return 0; | 859 | return 0; |
860 | 860 | ||
861 | case SNDCTL_COPR_LOAD: | 861 | case SNDCTL_COPR_LOAD: |
862 | buf = (copr_buffer *) vmalloc(sizeof(copr_buffer)); | 862 | buf = vmalloc(sizeof(copr_buffer)); |
863 | if (buf == NULL) | 863 | if (buf == NULL) |
864 | return -ENOSPC; | 864 | return -ENOSPC; |
865 | if (copy_from_user(buf, arg, sizeof(copr_buffer))) { | 865 | if (copy_from_user(buf, arg, sizeof(copr_buffer))) { |
@@ -871,7 +871,7 @@ static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, | |||
871 | return err; | 871 | return err; |
872 | 872 | ||
873 | case SNDCTL_COPR_SENDMSG: | 873 | case SNDCTL_COPR_SENDMSG: |
874 | mbuf = (copr_msg *)vmalloc(sizeof(copr_msg)); | 874 | mbuf = vmalloc(sizeof(copr_msg)); |
875 | if (mbuf == NULL) | 875 | if (mbuf == NULL) |
876 | return -ENOSPC; | 876 | return -ENOSPC; |
877 | if (copy_from_user(mbuf, arg, sizeof(copr_msg))) { | 877 | if (copy_from_user(mbuf, arg, sizeof(copr_msg))) { |
@@ -895,7 +895,7 @@ static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, | |||
895 | 895 | ||
896 | case SNDCTL_COPR_RCVMSG: | 896 | case SNDCTL_COPR_RCVMSG: |
897 | err = 0; | 897 | err = 0; |
898 | mbuf = (copr_msg *)vmalloc(sizeof(copr_msg)); | 898 | mbuf = vmalloc(sizeof(copr_msg)); |
899 | if (mbuf == NULL) | 899 | if (mbuf == NULL) |
900 | return -ENOSPC; | 900 | return -ENOSPC; |
901 | data = (unsigned short *)mbuf->data; | 901 | data = (unsigned short *)mbuf->data; |
diff --git a/sound/oss/sb_card.c b/sound/oss/sb_card.c index 84ef4d06c1c2..fb5d7250de38 100644 --- a/sound/oss/sb_card.c +++ b/sound/oss/sb_card.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * sound/oss/sb_card.c | 2 | * sound/oss/sb_card.c |
3 | * | 3 | * |
4 | * Detection routine for the ISA Sound Blaster and compatable sound | 4 | * Detection routine for the ISA Sound Blaster and compatible sound |
5 | * cards. | 5 | * cards. |
6 | * | 6 | * |
7 | * This file is distributed under the GNU GENERAL PUBLIC LICENSE (GPL) | 7 | * This file is distributed under the GNU GENERAL PUBLIC LICENSE (GPL) |
diff --git a/sound/oss/sb_ess.c b/sound/oss/sb_ess.c index 51a3d381a59e..5c773dff5ac5 100644 --- a/sound/oss/sb_ess.c +++ b/sound/oss/sb_ess.c | |||
@@ -168,7 +168,7 @@ | |||
168 | * corresponding playback levels, unless recmask says they aren't recorded. In | 168 | * corresponding playback levels, unless recmask says they aren't recorded. In |
169 | * the latter case the recording volumes are 0. | 169 | * the latter case the recording volumes are 0. |
170 | * Now recording levels of inputs can be controlled, by changing the playback | 170 | * Now recording levels of inputs can be controlled, by changing the playback |
171 | * levels. Futhermore several devices can be recorded together (which is not | 171 | * levels. Furthermore several devices can be recorded together (which is not |
172 | * possible with the ES1688). | 172 | * possible with the ES1688). |
173 | * Besides the separate recording level control for each input, the common | 173 | * Besides the separate recording level control for each input, the common |
174 | * recording level can also be controlled by RECLEV as described above. | 174 | * recording level can also be controlled by RECLEV as described above. |
@@ -1722,7 +1722,6 @@ printk (KERN_INFO "FKS: es_rec_set_recmask mask = %x\n", mask); | |||
1722 | right = (value & 0x0000ff00) >> 8; | 1722 | right = (value & 0x0000ff00) >> 8; |
1723 | } else { /* Turn it off (3) */ | 1723 | } else { /* Turn it off (3) */ |
1724 | left = 0; | 1724 | left = 0; |
1725 | left = 0; | ||
1726 | right = 0; | 1725 | right = 0; |
1727 | } | 1726 | } |
1728 | sb_common_mixer_set(devc, i + ES_REC_MIXER_RECDIFF, left, right); | 1727 | sb_common_mixer_set(devc, i + ES_REC_MIXER_RECDIFF, left, right); |
diff --git a/sound/oss/sequencer.c b/sound/oss/sequencer.c index e85789e53816..30bcfe470f83 100644 --- a/sound/oss/sequencer.c +++ b/sound/oss/sequencer.c | |||
@@ -241,7 +241,7 @@ int sequencer_write(int dev, struct file *file, const char __user *buf, int coun | |||
241 | return -ENXIO; | 241 | return -ENXIO; |
242 | 242 | ||
243 | fmt = (*(short *) &event_rec[0]) & 0xffff; | 243 | fmt = (*(short *) &event_rec[0]) & 0xffff; |
244 | err = synth_devs[dev]->load_patch(dev, fmt, buf, p + 4, c, 0); | 244 | err = synth_devs[dev]->load_patch(dev, fmt, buf + p, c, 0); |
245 | if (err < 0) | 245 | if (err < 0) |
246 | return err; | 246 | return err; |
247 | 247 | ||
@@ -1646,13 +1646,13 @@ void sequencer_init(void) | |||
1646 | { | 1646 | { |
1647 | if (sequencer_ok) | 1647 | if (sequencer_ok) |
1648 | return; | 1648 | return; |
1649 | queue = (unsigned char *)vmalloc(SEQ_MAX_QUEUE * EV_SZ); | 1649 | queue = vmalloc(SEQ_MAX_QUEUE * EV_SZ); |
1650 | if (queue == NULL) | 1650 | if (queue == NULL) |
1651 | { | 1651 | { |
1652 | printk(KERN_ERR "sequencer: Can't allocate memory for sequencer output queue\n"); | 1652 | printk(KERN_ERR "sequencer: Can't allocate memory for sequencer output queue\n"); |
1653 | return; | 1653 | return; |
1654 | } | 1654 | } |
1655 | iqueue = (unsigned char *)vmalloc(SEQ_MAX_QUEUE * IEV_SZ); | 1655 | iqueue = vmalloc(SEQ_MAX_QUEUE * IEV_SZ); |
1656 | if (iqueue == NULL) | 1656 | if (iqueue == NULL) |
1657 | { | 1657 | { |
1658 | printk(KERN_ERR "sequencer: Can't allocate memory for sequencer input queue\n"); | 1658 | printk(KERN_ERR "sequencer: Can't allocate memory for sequencer input queue\n"); |
diff --git a/sound/oss/sh_dac_audio.c b/sound/oss/sh_dac_audio.c deleted file mode 100644 index 479e3025a8a3..000000000000 --- a/sound/oss/sh_dac_audio.c +++ /dev/null | |||
@@ -1,325 +0,0 @@ | |||
1 | /* | ||
2 | * sound/oss/sh_dac_audio.c | ||
3 | * | ||
4 | * SH DAC based sound :( | ||
5 | * | ||
6 | * Copyright (C) 2004,2005 Andriy Skulysh | ||
7 | * | ||
8 | * This file is subject to the terms and conditions of the GNU General Public | ||
9 | * License. See the file "COPYING" in the main directory of this archive | ||
10 | * for more details. | ||
11 | */ | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/sched.h> | ||
15 | #include <linux/linkage.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/fs.h> | ||
18 | #include <linux/sound.h> | ||
19 | #include <linux/smp_lock.h> | ||
20 | #include <linux/soundcard.h> | ||
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/hrtimer.h> | ||
23 | #include <asm/io.h> | ||
24 | #include <asm/uaccess.h> | ||
25 | #include <asm/irq.h> | ||
26 | #include <asm/delay.h> | ||
27 | #include <asm/clock.h> | ||
28 | #include <cpu/dac.h> | ||
29 | #include <asm/machvec.h> | ||
30 | #include <mach/hp6xx.h> | ||
31 | #include <asm/hd64461.h> | ||
32 | |||
33 | #define MODNAME "sh_dac_audio" | ||
34 | |||
35 | #define BUFFER_SIZE 48000 | ||
36 | |||
37 | static int rate; | ||
38 | static int empty; | ||
39 | static char *data_buffer, *buffer_begin, *buffer_end; | ||
40 | static int in_use, device_major; | ||
41 | static struct hrtimer hrtimer; | ||
42 | static ktime_t wakeups_per_second; | ||
43 | |||
44 | static void dac_audio_start_timer(void) | ||
45 | { | ||
46 | hrtimer_start(&hrtimer, wakeups_per_second, HRTIMER_MODE_REL); | ||
47 | } | ||
48 | |||
49 | static void dac_audio_stop_timer(void) | ||
50 | { | ||
51 | hrtimer_cancel(&hrtimer); | ||
52 | } | ||
53 | |||
54 | static void dac_audio_reset(void) | ||
55 | { | ||
56 | dac_audio_stop_timer(); | ||
57 | buffer_begin = buffer_end = data_buffer; | ||
58 | empty = 1; | ||
59 | } | ||
60 | |||
61 | static void dac_audio_sync(void) | ||
62 | { | ||
63 | while (!empty) | ||
64 | schedule(); | ||
65 | } | ||
66 | |||
67 | static void dac_audio_start(void) | ||
68 | { | ||
69 | if (mach_is_hp6xx()) { | ||
70 | u16 v = __raw_readw(HD64461_GPADR); | ||
71 | v &= ~HD64461_GPADR_SPEAKER; | ||
72 | __raw_writew(v, HD64461_GPADR); | ||
73 | } | ||
74 | |||
75 | sh_dac_enable(CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL); | ||
76 | } | ||
77 | static void dac_audio_stop(void) | ||
78 | { | ||
79 | dac_audio_stop_timer(); | ||
80 | |||
81 | if (mach_is_hp6xx()) { | ||
82 | u16 v = __raw_readw(HD64461_GPADR); | ||
83 | v |= HD64461_GPADR_SPEAKER; | ||
84 | __raw_writew(v, HD64461_GPADR); | ||
85 | } | ||
86 | |||
87 | sh_dac_output(0, CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL); | ||
88 | sh_dac_disable(CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL); | ||
89 | } | ||
90 | |||
91 | static void dac_audio_set_rate(void) | ||
92 | { | ||
93 | wakeups_per_second = ktime_set(0, 1000000000 / rate); | ||
94 | } | ||
95 | |||
96 | static int dac_audio_ioctl(struct file *file, | ||
97 | unsigned int cmd, unsigned long arg) | ||
98 | { | ||
99 | int val; | ||
100 | |||
101 | switch (cmd) { | ||
102 | case OSS_GETVERSION: | ||
103 | return put_user(SOUND_VERSION, (int *)arg); | ||
104 | |||
105 | case SNDCTL_DSP_SYNC: | ||
106 | dac_audio_sync(); | ||
107 | return 0; | ||
108 | |||
109 | case SNDCTL_DSP_RESET: | ||
110 | dac_audio_reset(); | ||
111 | return 0; | ||
112 | |||
113 | case SNDCTL_DSP_GETFMTS: | ||
114 | return put_user(AFMT_U8, (int *)arg); | ||
115 | |||
116 | case SNDCTL_DSP_SETFMT: | ||
117 | return put_user(AFMT_U8, (int *)arg); | ||
118 | |||
119 | case SNDCTL_DSP_NONBLOCK: | ||
120 | spin_lock(&file->f_lock); | ||
121 | file->f_flags |= O_NONBLOCK; | ||
122 | spin_unlock(&file->f_lock); | ||
123 | return 0; | ||
124 | |||
125 | case SNDCTL_DSP_GETCAPS: | ||
126 | return 0; | ||
127 | |||
128 | case SOUND_PCM_WRITE_RATE: | ||
129 | val = *(int *)arg; | ||
130 | if (val > 0) { | ||
131 | rate = val; | ||
132 | dac_audio_set_rate(); | ||
133 | } | ||
134 | return put_user(rate, (int *)arg); | ||
135 | |||
136 | case SNDCTL_DSP_STEREO: | ||
137 | return put_user(0, (int *)arg); | ||
138 | |||
139 | case SOUND_PCM_WRITE_CHANNELS: | ||
140 | return put_user(1, (int *)arg); | ||
141 | |||
142 | case SNDCTL_DSP_SETDUPLEX: | ||
143 | return -EINVAL; | ||
144 | |||
145 | case SNDCTL_DSP_PROFILE: | ||
146 | return -EINVAL; | ||
147 | |||
148 | case SNDCTL_DSP_GETBLKSIZE: | ||
149 | return put_user(BUFFER_SIZE, (int *)arg); | ||
150 | |||
151 | case SNDCTL_DSP_SETFRAGMENT: | ||
152 | return 0; | ||
153 | |||
154 | default: | ||
155 | printk(KERN_ERR "sh_dac_audio: unimplemented ioctl=0x%x\n", | ||
156 | cmd); | ||
157 | return -EINVAL; | ||
158 | } | ||
159 | return -EINVAL; | ||
160 | } | ||
161 | |||
162 | static long dac_audio_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) | ||
163 | { | ||
164 | int ret; | ||
165 | |||
166 | lock_kernel(); | ||
167 | ret = dac_audio_ioctl(file, cmd, arg); | ||
168 | unlock_kernel(); | ||
169 | |||
170 | return ret; | ||
171 | } | ||
172 | |||
173 | static ssize_t dac_audio_write(struct file *file, const char *buf, size_t count, | ||
174 | loff_t * ppos) | ||
175 | { | ||
176 | int free; | ||
177 | int nbytes; | ||
178 | |||
179 | if (!count) { | ||
180 | dac_audio_sync(); | ||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | free = buffer_begin - buffer_end; | ||
185 | |||
186 | if (free < 0) | ||
187 | free += BUFFER_SIZE; | ||
188 | if ((free == 0) && (empty)) | ||
189 | free = BUFFER_SIZE; | ||
190 | if (count > free) | ||
191 | count = free; | ||
192 | if (buffer_begin > buffer_end) { | ||
193 | if (copy_from_user((void *)buffer_end, buf, count)) | ||
194 | return -EFAULT; | ||
195 | |||
196 | buffer_end += count; | ||
197 | } else { | ||
198 | nbytes = data_buffer + BUFFER_SIZE - buffer_end; | ||
199 | if (nbytes > count) { | ||
200 | if (copy_from_user((void *)buffer_end, buf, count)) | ||
201 | return -EFAULT; | ||
202 | buffer_end += count; | ||
203 | } else { | ||
204 | if (copy_from_user((void *)buffer_end, buf, nbytes)) | ||
205 | return -EFAULT; | ||
206 | if (copy_from_user | ||
207 | ((void *)data_buffer, buf + nbytes, count - nbytes)) | ||
208 | return -EFAULT; | ||
209 | buffer_end = data_buffer + count - nbytes; | ||
210 | } | ||
211 | } | ||
212 | |||
213 | if (empty) { | ||
214 | empty = 0; | ||
215 | dac_audio_start_timer(); | ||
216 | } | ||
217 | |||
218 | return count; | ||
219 | } | ||
220 | |||
221 | static ssize_t dac_audio_read(struct file *file, char *buf, size_t count, | ||
222 | loff_t * ppos) | ||
223 | { | ||
224 | return -EINVAL; | ||
225 | } | ||
226 | |||
227 | static int dac_audio_open(struct inode *inode, struct file *file) | ||
228 | { | ||
229 | if (file->f_mode & FMODE_READ) | ||
230 | return -ENODEV; | ||
231 | |||
232 | lock_kernel(); | ||
233 | if (in_use) { | ||
234 | unlock_kernel(); | ||
235 | return -EBUSY; | ||
236 | } | ||
237 | |||
238 | in_use = 1; | ||
239 | |||
240 | dac_audio_start(); | ||
241 | unlock_kernel(); | ||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | static int dac_audio_release(struct inode *inode, struct file *file) | ||
246 | { | ||
247 | dac_audio_sync(); | ||
248 | dac_audio_stop(); | ||
249 | in_use = 0; | ||
250 | |||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | const struct file_operations dac_audio_fops = { | ||
255 | .read = dac_audio_read, | ||
256 | .write = dac_audio_write, | ||
257 | .unlocked_ioctl = dac_audio_unlocked_ioctl, | ||
258 | .open = dac_audio_open, | ||
259 | .release = dac_audio_release, | ||
260 | }; | ||
261 | |||
262 | static enum hrtimer_restart sh_dac_audio_timer(struct hrtimer *handle) | ||
263 | { | ||
264 | if (!empty) { | ||
265 | sh_dac_output(*buffer_begin, CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL); | ||
266 | buffer_begin++; | ||
267 | |||
268 | if (buffer_begin == data_buffer + BUFFER_SIZE) | ||
269 | buffer_begin = data_buffer; | ||
270 | if (buffer_begin == buffer_end) | ||
271 | empty = 1; | ||
272 | } | ||
273 | |||
274 | if (!empty) | ||
275 | hrtimer_start(&hrtimer, wakeups_per_second, HRTIMER_MODE_REL); | ||
276 | |||
277 | return HRTIMER_NORESTART; | ||
278 | } | ||
279 | |||
280 | static int __init dac_audio_init(void) | ||
281 | { | ||
282 | if ((device_major = register_sound_dsp(&dac_audio_fops, -1)) < 0) { | ||
283 | printk(KERN_ERR "Cannot register dsp device"); | ||
284 | return device_major; | ||
285 | } | ||
286 | |||
287 | in_use = 0; | ||
288 | |||
289 | data_buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL); | ||
290 | if (data_buffer == NULL) | ||
291 | return -ENOMEM; | ||
292 | |||
293 | dac_audio_reset(); | ||
294 | rate = 8000; | ||
295 | dac_audio_set_rate(); | ||
296 | |||
297 | /* Today: High Resolution Timer driven DAC playback. | ||
298 | * The timer callback gets called once per sample. Ouch. | ||
299 | * | ||
300 | * Future: A much better approach would be to use the | ||
301 | * SH7720 CMT+DMAC+DAC hardware combination like this: | ||
302 | * - Program sample rate using CMT0 or CMT1 | ||
303 | * - Program DMAC to use CMT for timing and output to DAC | ||
304 | * - Play sound using DMAC, let CPU sleep. | ||
305 | * - While at it, rewrite this driver to use ALSA. | ||
306 | */ | ||
307 | |||
308 | hrtimer_init(&hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
309 | hrtimer.function = sh_dac_audio_timer; | ||
310 | |||
311 | return 0; | ||
312 | } | ||
313 | |||
314 | static void __exit dac_audio_exit(void) | ||
315 | { | ||
316 | unregister_sound_dsp(device_major); | ||
317 | kfree((void *)data_buffer); | ||
318 | } | ||
319 | |||
320 | module_init(dac_audio_init); | ||
321 | module_exit(dac_audio_exit); | ||
322 | |||
323 | MODULE_AUTHOR("Andriy Skulysh, askulysh@image.kiev.ua"); | ||
324 | MODULE_DESCRIPTION("SH DAC sound driver"); | ||
325 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c index 07f803e6d203..7c7793a0eb25 100644 --- a/sound/oss/soundcard.c +++ b/sound/oss/soundcard.c | |||
@@ -40,7 +40,7 @@ | |||
40 | #include <linux/major.h> | 40 | #include <linux/major.h> |
41 | #include <linux/delay.h> | 41 | #include <linux/delay.h> |
42 | #include <linux/proc_fs.h> | 42 | #include <linux/proc_fs.h> |
43 | #include <linux/smp_lock.h> | 43 | #include <linux/mutex.h> |
44 | #include <linux/module.h> | 44 | #include <linux/module.h> |
45 | #include <linux/mm.h> | 45 | #include <linux/mm.h> |
46 | #include <linux/device.h> | 46 | #include <linux/device.h> |
@@ -56,6 +56,7 @@ | |||
56 | * Table for permanently allocated memory (used when unloading the module) | 56 | * Table for permanently allocated memory (used when unloading the module) |
57 | */ | 57 | */ |
58 | void * sound_mem_blocks[MAX_MEM_BLOCKS]; | 58 | void * sound_mem_blocks[MAX_MEM_BLOCKS]; |
59 | static DEFINE_MUTEX(soundcard_mutex); | ||
59 | int sound_nblocks = 0; | 60 | int sound_nblocks = 0; |
60 | 61 | ||
61 | /* Persistent DMA buffers */ | 62 | /* Persistent DMA buffers */ |
@@ -86,7 +87,7 @@ int *load_mixer_volumes(char *name, int *levels, int present) | |||
86 | int i, n; | 87 | int i, n; |
87 | 88 | ||
88 | for (i = 0; i < num_mixer_volumes; i++) { | 89 | for (i = 0; i < num_mixer_volumes; i++) { |
89 | if (strcmp(name, mixer_vols[i].name) == 0) { | 90 | if (strncmp(name, mixer_vols[i].name, 32) == 0) { |
90 | if (present) | 91 | if (present) |
91 | mixer_vols[i].num = i; | 92 | mixer_vols[i].num = i; |
92 | return mixer_vols[i].levels; | 93 | return mixer_vols[i].levels; |
@@ -98,7 +99,7 @@ int *load_mixer_volumes(char *name, int *levels, int present) | |||
98 | } | 99 | } |
99 | n = num_mixer_volumes++; | 100 | n = num_mixer_volumes++; |
100 | 101 | ||
101 | strcpy(mixer_vols[n].name, name); | 102 | strncpy(mixer_vols[n].name, name, 32); |
102 | 103 | ||
103 | if (present) | 104 | if (present) |
104 | mixer_vols[n].num = n; | 105 | mixer_vols[n].num = n; |
@@ -151,7 +152,7 @@ static ssize_t sound_read(struct file *file, char __user *buf, size_t count, lof | |||
151 | * big one anyway, we might as well bandage here.. | 152 | * big one anyway, we might as well bandage here.. |
152 | */ | 153 | */ |
153 | 154 | ||
154 | lock_kernel(); | 155 | mutex_lock(&soundcard_mutex); |
155 | 156 | ||
156 | DEB(printk("sound_read(dev=%d, count=%d)\n", dev, count)); | 157 | DEB(printk("sound_read(dev=%d, count=%d)\n", dev, count)); |
157 | switch (dev & 0x0f) { | 158 | switch (dev & 0x0f) { |
@@ -169,7 +170,7 @@ static ssize_t sound_read(struct file *file, char __user *buf, size_t count, lof | |||
169 | case SND_DEV_MIDIN: | 170 | case SND_DEV_MIDIN: |
170 | ret = MIDIbuf_read(dev, file, buf, count); | 171 | ret = MIDIbuf_read(dev, file, buf, count); |
171 | } | 172 | } |
172 | unlock_kernel(); | 173 | mutex_unlock(&soundcard_mutex); |
173 | return ret; | 174 | return ret; |
174 | } | 175 | } |
175 | 176 | ||
@@ -178,7 +179,7 @@ static ssize_t sound_write(struct file *file, const char __user *buf, size_t cou | |||
178 | int dev = iminor(file->f_path.dentry->d_inode); | 179 | int dev = iminor(file->f_path.dentry->d_inode); |
179 | int ret = -EINVAL; | 180 | int ret = -EINVAL; |
180 | 181 | ||
181 | lock_kernel(); | 182 | mutex_lock(&soundcard_mutex); |
182 | DEB(printk("sound_write(dev=%d, count=%d)\n", dev, count)); | 183 | DEB(printk("sound_write(dev=%d, count=%d)\n", dev, count)); |
183 | switch (dev & 0x0f) { | 184 | switch (dev & 0x0f) { |
184 | case SND_DEV_SEQ: | 185 | case SND_DEV_SEQ: |
@@ -196,7 +197,7 @@ static ssize_t sound_write(struct file *file, const char __user *buf, size_t cou | |||
196 | ret = MIDIbuf_write(dev, file, buf, count); | 197 | ret = MIDIbuf_write(dev, file, buf, count); |
197 | break; | 198 | break; |
198 | } | 199 | } |
199 | unlock_kernel(); | 200 | mutex_unlock(&soundcard_mutex); |
200 | return ret; | 201 | return ret; |
201 | } | 202 | } |
202 | 203 | ||
@@ -210,7 +211,7 @@ static int sound_open(struct inode *inode, struct file *file) | |||
210 | printk(KERN_ERR "Invalid minor device %d\n", dev); | 211 | printk(KERN_ERR "Invalid minor device %d\n", dev); |
211 | return -ENXIO; | 212 | return -ENXIO; |
212 | } | 213 | } |
213 | lock_kernel(); | 214 | mutex_lock(&soundcard_mutex); |
214 | switch (dev & 0x0f) { | 215 | switch (dev & 0x0f) { |
215 | case SND_DEV_CTL: | 216 | case SND_DEV_CTL: |
216 | dev >>= 4; | 217 | dev >>= 4; |
@@ -247,15 +248,15 @@ static int sound_open(struct inode *inode, struct file *file) | |||
247 | retval = -ENXIO; | 248 | retval = -ENXIO; |
248 | } | 249 | } |
249 | 250 | ||
250 | unlock_kernel(); | 251 | mutex_unlock(&soundcard_mutex); |
251 | return 0; | 252 | return retval; |
252 | } | 253 | } |
253 | 254 | ||
254 | static int sound_release(struct inode *inode, struct file *file) | 255 | static int sound_release(struct inode *inode, struct file *file) |
255 | { | 256 | { |
256 | int dev = iminor(inode); | 257 | int dev = iminor(inode); |
257 | 258 | ||
258 | lock_kernel(); | 259 | mutex_lock(&soundcard_mutex); |
259 | DEB(printk("sound_release(dev=%d)\n", dev)); | 260 | DEB(printk("sound_release(dev=%d)\n", dev)); |
260 | switch (dev & 0x0f) { | 261 | switch (dev & 0x0f) { |
261 | case SND_DEV_CTL: | 262 | case SND_DEV_CTL: |
@@ -280,7 +281,7 @@ static int sound_release(struct inode *inode, struct file *file) | |||
280 | default: | 281 | default: |
281 | printk(KERN_ERR "Sound error: Releasing unknown device 0x%02x\n", dev); | 282 | printk(KERN_ERR "Sound error: Releasing unknown device 0x%02x\n", dev); |
282 | } | 283 | } |
283 | unlock_kernel(); | 284 | mutex_unlock(&soundcard_mutex); |
284 | 285 | ||
285 | return 0; | 286 | return 0; |
286 | } | 287 | } |
@@ -354,7 +355,7 @@ static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
354 | if (cmd == OSS_GETVERSION) | 355 | if (cmd == OSS_GETVERSION) |
355 | return __put_user(SOUND_VERSION, (int __user *)p); | 356 | return __put_user(SOUND_VERSION, (int __user *)p); |
356 | 357 | ||
357 | lock_kernel(); | 358 | mutex_lock(&soundcard_mutex); |
358 | if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 && /* Mixer ioctl */ | 359 | if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 && /* Mixer ioctl */ |
359 | (dev & 0x0f) != SND_DEV_CTL) { | 360 | (dev & 0x0f) != SND_DEV_CTL) { |
360 | dtype = dev & 0x0f; | 361 | dtype = dev & 0x0f; |
@@ -369,7 +370,7 @@ static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
369 | ret = sound_mixer_ioctl(dev >> 4, cmd, p); | 370 | ret = sound_mixer_ioctl(dev >> 4, cmd, p); |
370 | break; | 371 | break; |
371 | } | 372 | } |
372 | unlock_kernel(); | 373 | mutex_unlock(&soundcard_mutex); |
373 | return ret; | 374 | return ret; |
374 | } | 375 | } |
375 | 376 | ||
@@ -399,7 +400,7 @@ static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
399 | break; | 400 | break; |
400 | 401 | ||
401 | } | 402 | } |
402 | unlock_kernel(); | 403 | mutex_unlock(&soundcard_mutex); |
403 | return ret; | 404 | return ret; |
404 | } | 405 | } |
405 | 406 | ||
@@ -439,35 +440,35 @@ static int sound_mmap(struct file *file, struct vm_area_struct *vma) | |||
439 | printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n"); | 440 | printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n"); |
440 | return -EINVAL; | 441 | return -EINVAL; |
441 | } | 442 | } |
442 | lock_kernel(); | 443 | mutex_lock(&soundcard_mutex); |
443 | if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */ | 444 | if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */ |
444 | dmap = audio_devs[dev]->dmap_out; | 445 | dmap = audio_devs[dev]->dmap_out; |
445 | else if (vma->vm_flags & VM_READ) | 446 | else if (vma->vm_flags & VM_READ) |
446 | dmap = audio_devs[dev]->dmap_in; | 447 | dmap = audio_devs[dev]->dmap_in; |
447 | else { | 448 | else { |
448 | printk(KERN_ERR "Sound: Undefined mmap() access\n"); | 449 | printk(KERN_ERR "Sound: Undefined mmap() access\n"); |
449 | unlock_kernel(); | 450 | mutex_unlock(&soundcard_mutex); |
450 | return -EINVAL; | 451 | return -EINVAL; |
451 | } | 452 | } |
452 | 453 | ||
453 | if (dmap == NULL) { | 454 | if (dmap == NULL) { |
454 | printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n"); | 455 | printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n"); |
455 | unlock_kernel(); | 456 | mutex_unlock(&soundcard_mutex); |
456 | return -EIO; | 457 | return -EIO; |
457 | } | 458 | } |
458 | if (dmap->raw_buf == NULL) { | 459 | if (dmap->raw_buf == NULL) { |
459 | printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n"); | 460 | printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n"); |
460 | unlock_kernel(); | 461 | mutex_unlock(&soundcard_mutex); |
461 | return -EIO; | 462 | return -EIO; |
462 | } | 463 | } |
463 | if (dmap->mapping_flags) { | 464 | if (dmap->mapping_flags) { |
464 | printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n"); | 465 | printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n"); |
465 | unlock_kernel(); | 466 | mutex_unlock(&soundcard_mutex); |
466 | return -EIO; | 467 | return -EIO; |
467 | } | 468 | } |
468 | if (vma->vm_pgoff != 0) { | 469 | if (vma->vm_pgoff != 0) { |
469 | printk(KERN_ERR "Sound: mmap() offset must be 0.\n"); | 470 | printk(KERN_ERR "Sound: mmap() offset must be 0.\n"); |
470 | unlock_kernel(); | 471 | mutex_unlock(&soundcard_mutex); |
471 | return -EINVAL; | 472 | return -EINVAL; |
472 | } | 473 | } |
473 | size = vma->vm_end - vma->vm_start; | 474 | size = vma->vm_end - vma->vm_start; |
@@ -478,7 +479,7 @@ static int sound_mmap(struct file *file, struct vm_area_struct *vma) | |||
478 | if (remap_pfn_range(vma, vma->vm_start, | 479 | if (remap_pfn_range(vma, vma->vm_start, |
479 | virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT, | 480 | virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT, |
480 | vma->vm_end - vma->vm_start, vma->vm_page_prot)) { | 481 | vma->vm_end - vma->vm_start, vma->vm_page_prot)) { |
481 | unlock_kernel(); | 482 | mutex_unlock(&soundcard_mutex); |
482 | return -EAGAIN; | 483 | return -EAGAIN; |
483 | } | 484 | } |
484 | 485 | ||
@@ -490,7 +491,7 @@ static int sound_mmap(struct file *file, struct vm_area_struct *vma) | |||
490 | memset(dmap->raw_buf, | 491 | memset(dmap->raw_buf, |
491 | dmap->neutral_byte, | 492 | dmap->neutral_byte, |
492 | dmap->bytes_in_use); | 493 | dmap->bytes_in_use); |
493 | unlock_kernel(); | 494 | mutex_unlock(&soundcard_mutex); |
494 | return 0; | 495 | return 0; |
495 | } | 496 | } |
496 | 497 | ||
@@ -525,31 +526,21 @@ bad: | |||
525 | } | 526 | } |
526 | 527 | ||
527 | 528 | ||
528 | /* These device names follow the official Linux device list, | ||
529 | * Documentation/devices.txt. Let us know if there are other | ||
530 | * common names we should support for compatibility. | ||
531 | * Only those devices not created by the generic code in sound_core.c are | ||
532 | * registered here. | ||
533 | */ | ||
534 | static const struct { | ||
535 | unsigned short minor; | ||
536 | char *name; | ||
537 | umode_t mode; | ||
538 | int *num; | ||
539 | } dev_list[] = { /* list of minor devices */ | ||
540 | /* seems to be some confusion here -- this device is not in the device list */ | ||
541 | {SND_DEV_DSP16, "dspW", S_IWUGO | S_IRUSR | S_IRGRP, | ||
542 | &num_audiodevs}, | ||
543 | {SND_DEV_AUDIO, "audio", S_IWUGO | S_IRUSR | S_IRGRP, | ||
544 | &num_audiodevs}, | ||
545 | }; | ||
546 | |||
547 | static int dmabuf; | 529 | static int dmabuf; |
548 | static int dmabug; | 530 | static int dmabug; |
549 | 531 | ||
550 | module_param(dmabuf, int, 0444); | 532 | module_param(dmabuf, int, 0444); |
551 | module_param(dmabug, int, 0444); | 533 | module_param(dmabug, int, 0444); |
552 | 534 | ||
535 | /* additional minors for compatibility */ | ||
536 | struct oss_minor_dev { | ||
537 | unsigned short minor; | ||
538 | unsigned int enabled; | ||
539 | } dev_list[] = { | ||
540 | { SND_DEV_DSP16 }, | ||
541 | { SND_DEV_AUDIO }, | ||
542 | }; | ||
543 | |||
553 | static int __init oss_init(void) | 544 | static int __init oss_init(void) |
554 | { | 545 | { |
555 | int err; | 546 | int err; |
@@ -570,18 +561,12 @@ static int __init oss_init(void) | |||
570 | sound_dmap_flag = (dmabuf > 0 ? 1 : 0); | 561 | sound_dmap_flag = (dmabuf > 0 ? 1 : 0); |
571 | 562 | ||
572 | for (i = 0; i < ARRAY_SIZE(dev_list); i++) { | 563 | for (i = 0; i < ARRAY_SIZE(dev_list); i++) { |
573 | device_create(sound_class, NULL, | 564 | j = 0; |
574 | MKDEV(SOUND_MAJOR, dev_list[i].minor), NULL, | 565 | do { |
575 | "%s", dev_list[i].name); | 566 | unsigned short minor = dev_list[i].minor + j * 0x10; |
576 | 567 | if (!register_sound_special(&oss_sound_fops, minor)) | |
577 | if (!dev_list[i].num) | 568 | dev_list[i].enabled = (1 << j); |
578 | continue; | 569 | } while (++j < num_audiodevs); |
579 | |||
580 | for (j = 1; j < *dev_list[i].num; j++) | ||
581 | device_create(sound_class, NULL, | ||
582 | MKDEV(SOUND_MAJOR, | ||
583 | dev_list[i].minor + (j*0x10)), | ||
584 | NULL, "%s%d", dev_list[i].name, j); | ||
585 | } | 570 | } |
586 | 571 | ||
587 | if (sound_nblocks >= MAX_MEM_BLOCKS - 1) | 572 | if (sound_nblocks >= MAX_MEM_BLOCKS - 1) |
@@ -595,11 +580,11 @@ static void __exit oss_cleanup(void) | |||
595 | int i, j; | 580 | int i, j; |
596 | 581 | ||
597 | for (i = 0; i < ARRAY_SIZE(dev_list); i++) { | 582 | for (i = 0; i < ARRAY_SIZE(dev_list); i++) { |
598 | device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor)); | 583 | j = 0; |
599 | if (!dev_list[i].num) | 584 | do { |
600 | continue; | 585 | if (dev_list[i].enabled & (1 << j)) |
601 | for (j = 1; j < *dev_list[i].num; j++) | 586 | unregister_sound_special(dev_list[i].minor); |
602 | device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10))); | 587 | } while (++j < num_audiodevs); |
603 | } | 588 | } |
604 | 589 | ||
605 | unregister_sound_special(1); | 590 | unregister_sound_special(1); |
diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c index b15840ad2527..09d46484bc1a 100644 --- a/sound/oss/swarm_cs4297a.c +++ b/sound/oss/swarm_cs4297a.c | |||
@@ -68,7 +68,6 @@ | |||
68 | #include <linux/delay.h> | 68 | #include <linux/delay.h> |
69 | #include <linux/sound.h> | 69 | #include <linux/sound.h> |
70 | #include <linux/slab.h> | 70 | #include <linux/slab.h> |
71 | #include <linux/smp_lock.h> | ||
72 | #include <linux/soundcard.h> | 71 | #include <linux/soundcard.h> |
73 | #include <linux/ac97_codec.h> | 72 | #include <linux/ac97_codec.h> |
74 | #include <linux/pci.h> | 73 | #include <linux/pci.h> |
@@ -94,6 +93,7 @@ | |||
94 | 93 | ||
95 | struct cs4297a_state; | 94 | struct cs4297a_state; |
96 | 95 | ||
96 | static DEFINE_MUTEX(swarm_cs4297a_mutex); | ||
97 | static void stop_dac(struct cs4297a_state *s); | 97 | static void stop_dac(struct cs4297a_state *s); |
98 | static void stop_adc(struct cs4297a_state *s); | 98 | static void stop_adc(struct cs4297a_state *s); |
99 | static void start_dac(struct cs4297a_state *s); | 99 | static void start_dac(struct cs4297a_state *s); |
@@ -875,7 +875,7 @@ static void start_adc(struct cs4297a_state *s) | |||
875 | if (s->prop_adc.fmt & AFMT_S8 || s->prop_adc.fmt & AFMT_U8) { | 875 | if (s->prop_adc.fmt & AFMT_S8 || s->prop_adc.fmt & AFMT_U8) { |
876 | // | 876 | // |
877 | // now only use 16 bit capture, due to truncation issue | 877 | // now only use 16 bit capture, due to truncation issue |
878 | // in the chip, noticable distortion occurs. | 878 | // in the chip, noticeable distortion occurs. |
879 | // allocate buffer and then convert from 16 bit to | 879 | // allocate buffer and then convert from 16 bit to |
880 | // 8 bit for the user buffer. | 880 | // 8 bit for the user buffer. |
881 | // | 881 | // |
@@ -1535,7 +1535,7 @@ static int cs4297a_open_mixdev(struct inode *inode, struct file *file) | |||
1535 | CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4, | 1535 | CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4, |
1536 | printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()+\n")); | 1536 | printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()+\n")); |
1537 | 1537 | ||
1538 | lock_kernel(); | 1538 | mutex_lock(&swarm_cs4297a_mutex); |
1539 | list_for_each(entry, &cs4297a_devs) | 1539 | list_for_each(entry, &cs4297a_devs) |
1540 | { | 1540 | { |
1541 | s = list_entry(entry, struct cs4297a_state, list); | 1541 | s = list_entry(entry, struct cs4297a_state, list); |
@@ -1547,7 +1547,7 @@ static int cs4297a_open_mixdev(struct inode *inode, struct file *file) | |||
1547 | CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2, | 1547 | CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2, |
1548 | printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()- -ENODEV\n")); | 1548 | printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()- -ENODEV\n")); |
1549 | 1549 | ||
1550 | unlock_kernel(); | 1550 | mutex_unlock(&swarm_cs4297a_mutex); |
1551 | return -ENODEV; | 1551 | return -ENODEV; |
1552 | } | 1552 | } |
1553 | VALIDATE_STATE(s); | 1553 | VALIDATE_STATE(s); |
@@ -1555,7 +1555,7 @@ static int cs4297a_open_mixdev(struct inode *inode, struct file *file) | |||
1555 | 1555 | ||
1556 | CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4, | 1556 | CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4, |
1557 | printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()- 0\n")); | 1557 | printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()- 0\n")); |
1558 | unlock_kernel(); | 1558 | mutex_unlock(&swarm_cs4297a_mutex); |
1559 | 1559 | ||
1560 | return nonseekable_open(inode, file); | 1560 | return nonseekable_open(inode, file); |
1561 | } | 1561 | } |
@@ -1575,10 +1575,10 @@ static int cs4297a_ioctl_mixdev(struct file *file, | |||
1575 | unsigned int cmd, unsigned long arg) | 1575 | unsigned int cmd, unsigned long arg) |
1576 | { | 1576 | { |
1577 | int ret; | 1577 | int ret; |
1578 | lock_kernel(); | 1578 | mutex_lock(&swarm_cs4297a_mutex); |
1579 | ret = mixer_ioctl((struct cs4297a_state *) file->private_data, cmd, | 1579 | ret = mixer_ioctl((struct cs4297a_state *) file->private_data, cmd, |
1580 | arg); | 1580 | arg); |
1581 | unlock_kernel(); | 1581 | mutex_unlock(&swarm_cs4297a_mutex); |
1582 | return ret; | 1582 | return ret; |
1583 | } | 1583 | } |
1584 | 1584 | ||
@@ -2350,9 +2350,9 @@ static long cs4297a_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) | |||
2350 | { | 2350 | { |
2351 | int ret; | 2351 | int ret; |
2352 | 2352 | ||
2353 | lock_kernel(); | 2353 | mutex_lock(&swarm_cs4297a_mutex); |
2354 | ret = cs4297a_ioctl(file, cmd, arg); | 2354 | ret = cs4297a_ioctl(file, cmd, arg); |
2355 | unlock_kernel(); | 2355 | mutex_unlock(&swarm_cs4297a_mutex); |
2356 | 2356 | ||
2357 | return ret; | 2357 | return ret; |
2358 | } | 2358 | } |
@@ -2509,9 +2509,9 @@ static int cs4297a_open(struct inode *inode, struct file *file) | |||
2509 | { | 2509 | { |
2510 | int ret; | 2510 | int ret; |
2511 | 2511 | ||
2512 | lock_kernel(); | 2512 | mutex_lock(&swarm_cs4297a_mutex); |
2513 | ret = cs4297a_open(inode, file); | 2513 | ret = cs4297a_open(inode, file); |
2514 | unlock_kernel(); | 2514 | mutex_unlock(&swarm_cs4297a_mutex); |
2515 | 2515 | ||
2516 | return ret; | 2516 | return ret; |
2517 | } | 2517 | } |
diff --git a/sound/oss/vidc.c b/sound/oss/vidc.c index f0e0caa53200..12ba28e7b933 100644 --- a/sound/oss/vidc.c +++ b/sound/oss/vidc.c | |||
@@ -227,7 +227,7 @@ static int vidc_audio_set_speed(int dev, int rate) | |||
227 | } else { | 227 | } else { |
228 | /*printk("VIDC: internal %d %d %d\n", rate, rate_int, hwrate);*/ | 228 | /*printk("VIDC: internal %d %d %d\n", rate, rate_int, hwrate);*/ |
229 | hwctrl=0x00000003; | 229 | hwctrl=0x00000003; |
230 | /* Allow rougly 0.4% tolerance */ | 230 | /* Allow roughly 0.4% tolerance */ |
231 | if (diff_int > (rate/256)) | 231 | if (diff_int > (rate/256)) |
232 | rate=rate_int; | 232 | rate=rate_int; |
233 | } | 233 | } |
diff --git a/sound/oss/vwsnd.c b/sound/oss/vwsnd.c index 8cd73cdd88af..643f1113b1d8 100644 --- a/sound/oss/vwsnd.c +++ b/sound/oss/vwsnd.c | |||
@@ -145,7 +145,6 @@ | |||
145 | #include <linux/init.h> | 145 | #include <linux/init.h> |
146 | 146 | ||
147 | #include <linux/spinlock.h> | 147 | #include <linux/spinlock.h> |
148 | #include <linux/smp_lock.h> | ||
149 | #include <linux/wait.h> | 148 | #include <linux/wait.h> |
150 | #include <linux/interrupt.h> | 149 | #include <linux/interrupt.h> |
151 | #include <linux/mutex.h> | 150 | #include <linux/mutex.h> |
@@ -160,6 +159,7 @@ | |||
160 | 159 | ||
161 | #ifdef VWSND_DEBUG | 160 | #ifdef VWSND_DEBUG |
162 | 161 | ||
162 | static DEFINE_MUTEX(vwsnd_mutex); | ||
163 | static int shut_up = 1; | 163 | static int shut_up = 1; |
164 | 164 | ||
165 | /* | 165 | /* |
@@ -2891,11 +2891,11 @@ static long vwsnd_audio_ioctl(struct file *file, | |||
2891 | vwsnd_dev_t *devc = (vwsnd_dev_t *) file->private_data; | 2891 | vwsnd_dev_t *devc = (vwsnd_dev_t *) file->private_data; |
2892 | int ret; | 2892 | int ret; |
2893 | 2893 | ||
2894 | lock_kernel(); | 2894 | mutex_lock(&vwsnd_mutex); |
2895 | mutex_lock(&devc->io_mutex); | 2895 | mutex_lock(&devc->io_mutex); |
2896 | ret = vwsnd_audio_do_ioctl(file, cmd, arg); | 2896 | ret = vwsnd_audio_do_ioctl(file, cmd, arg); |
2897 | mutex_unlock(&devc->io_mutex); | 2897 | mutex_unlock(&devc->io_mutex); |
2898 | unlock_kernel(); | 2898 | mutex_unlock(&vwsnd_mutex); |
2899 | 2899 | ||
2900 | return ret; | 2900 | return ret; |
2901 | } | 2901 | } |
@@ -2922,7 +2922,7 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file) | |||
2922 | 2922 | ||
2923 | DBGE("(inode=0x%p, file=0x%p)\n", inode, file); | 2923 | DBGE("(inode=0x%p, file=0x%p)\n", inode, file); |
2924 | 2924 | ||
2925 | lock_kernel(); | 2925 | mutex_lock(&vwsnd_mutex); |
2926 | INC_USE_COUNT; | 2926 | INC_USE_COUNT; |
2927 | for (devc = vwsnd_dev_list; devc; devc = devc->next_dev) | 2927 | for (devc = vwsnd_dev_list; devc; devc = devc->next_dev) |
2928 | if ((devc->audio_minor & ~0x0F) == (minor & ~0x0F)) | 2928 | if ((devc->audio_minor & ~0x0F) == (minor & ~0x0F)) |
@@ -2930,7 +2930,7 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file) | |||
2930 | 2930 | ||
2931 | if (devc == NULL) { | 2931 | if (devc == NULL) { |
2932 | DEC_USE_COUNT; | 2932 | DEC_USE_COUNT; |
2933 | unlock_kernel(); | 2933 | mutex_unlock(&vwsnd_mutex); |
2934 | return -ENODEV; | 2934 | return -ENODEV; |
2935 | } | 2935 | } |
2936 | 2936 | ||
@@ -2939,13 +2939,13 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file) | |||
2939 | mutex_unlock(&devc->open_mutex); | 2939 | mutex_unlock(&devc->open_mutex); |
2940 | if (file->f_flags & O_NONBLOCK) { | 2940 | if (file->f_flags & O_NONBLOCK) { |
2941 | DEC_USE_COUNT; | 2941 | DEC_USE_COUNT; |
2942 | unlock_kernel(); | 2942 | mutex_unlock(&vwsnd_mutex); |
2943 | return -EBUSY; | 2943 | return -EBUSY; |
2944 | } | 2944 | } |
2945 | interruptible_sleep_on(&devc->open_wait); | 2945 | interruptible_sleep_on(&devc->open_wait); |
2946 | if (signal_pending(current)) { | 2946 | if (signal_pending(current)) { |
2947 | DEC_USE_COUNT; | 2947 | DEC_USE_COUNT; |
2948 | unlock_kernel(); | 2948 | mutex_unlock(&vwsnd_mutex); |
2949 | return -ERESTARTSYS; | 2949 | return -ERESTARTSYS; |
2950 | } | 2950 | } |
2951 | mutex_lock(&devc->open_mutex); | 2951 | mutex_lock(&devc->open_mutex); |
@@ -2998,7 +2998,7 @@ static int vwsnd_audio_open(struct inode *inode, struct file *file) | |||
2998 | 2998 | ||
2999 | file->private_data = devc; | 2999 | file->private_data = devc; |
3000 | DBGRV(); | 3000 | DBGRV(); |
3001 | unlock_kernel(); | 3001 | mutex_unlock(&vwsnd_mutex); |
3002 | return 0; | 3002 | return 0; |
3003 | } | 3003 | } |
3004 | 3004 | ||
@@ -3012,7 +3012,7 @@ static int vwsnd_audio_release(struct inode *inode, struct file *file) | |||
3012 | vwsnd_port_t *wport = NULL, *rport = NULL; | 3012 | vwsnd_port_t *wport = NULL, *rport = NULL; |
3013 | int err = 0; | 3013 | int err = 0; |
3014 | 3014 | ||
3015 | lock_kernel(); | 3015 | mutex_lock(&vwsnd_mutex); |
3016 | mutex_lock(&devc->io_mutex); | 3016 | mutex_lock(&devc->io_mutex); |
3017 | { | 3017 | { |
3018 | DBGEV("(inode=0x%p, file=0x%p)\n", inode, file); | 3018 | DBGEV("(inode=0x%p, file=0x%p)\n", inode, file); |
@@ -3040,7 +3040,7 @@ static int vwsnd_audio_release(struct inode *inode, struct file *file) | |||
3040 | wake_up(&devc->open_wait); | 3040 | wake_up(&devc->open_wait); |
3041 | DEC_USE_COUNT; | 3041 | DEC_USE_COUNT; |
3042 | DBGR(); | 3042 | DBGR(); |
3043 | unlock_kernel(); | 3043 | mutex_unlock(&vwsnd_mutex); |
3044 | return err; | 3044 | return err; |
3045 | } | 3045 | } |
3046 | 3046 | ||
@@ -3068,18 +3068,18 @@ static int vwsnd_mixer_open(struct inode *inode, struct file *file) | |||
3068 | DBGEV("(inode=0x%p, file=0x%p)\n", inode, file); | 3068 | DBGEV("(inode=0x%p, file=0x%p)\n", inode, file); |
3069 | 3069 | ||
3070 | INC_USE_COUNT; | 3070 | INC_USE_COUNT; |
3071 | lock_kernel(); | 3071 | mutex_lock(&vwsnd_mutex); |
3072 | for (devc = vwsnd_dev_list; devc; devc = devc->next_dev) | 3072 | for (devc = vwsnd_dev_list; devc; devc = devc->next_dev) |
3073 | if (devc->mixer_minor == iminor(inode)) | 3073 | if (devc->mixer_minor == iminor(inode)) |
3074 | break; | 3074 | break; |
3075 | 3075 | ||
3076 | if (devc == NULL) { | 3076 | if (devc == NULL) { |
3077 | DEC_USE_COUNT; | 3077 | DEC_USE_COUNT; |
3078 | unlock_kernel(); | 3078 | mutex_unlock(&vwsnd_mutex); |
3079 | return -ENODEV; | 3079 | return -ENODEV; |
3080 | } | 3080 | } |
3081 | file->private_data = devc; | 3081 | file->private_data = devc; |
3082 | unlock_kernel(); | 3082 | mutex_unlock(&vwsnd_mutex); |
3083 | return 0; | 3083 | return 0; |
3084 | } | 3084 | } |
3085 | 3085 | ||
@@ -3223,7 +3223,7 @@ static long vwsnd_mixer_ioctl(struct file *file, | |||
3223 | 3223 | ||
3224 | DBGEV("(devc=0x%p, cmd=0x%x, arg=0x%lx)\n", devc, cmd, arg); | 3224 | DBGEV("(devc=0x%p, cmd=0x%x, arg=0x%lx)\n", devc, cmd, arg); |
3225 | 3225 | ||
3226 | lock_kernel(); | 3226 | mutex_lock(&vwsnd_mutex); |
3227 | mutex_lock(&devc->mix_mutex); | 3227 | mutex_lock(&devc->mix_mutex); |
3228 | { | 3228 | { |
3229 | if ((cmd & ~nrmask) == MIXER_READ(0)) | 3229 | if ((cmd & ~nrmask) == MIXER_READ(0)) |
@@ -3234,7 +3234,7 @@ static long vwsnd_mixer_ioctl(struct file *file, | |||
3234 | retval = -EINVAL; | 3234 | retval = -EINVAL; |
3235 | } | 3235 | } |
3236 | mutex_unlock(&devc->mix_mutex); | 3236 | mutex_unlock(&devc->mix_mutex); |
3237 | unlock_kernel(); | 3237 | mutex_unlock(&vwsnd_mutex); |
3238 | return retval; | 3238 | return retval; |
3239 | } | 3239 | } |
3240 | 3240 | ||