blob: 1688f07a14b09cafc745cf9c82cf2b5ef3dd3e8b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02002 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Routines for control of CS4231(A)/CS4232/InterWave & compatible chips
4 *
5 * Bugs:
Krzysztof Helt9295aea2008-07-31 21:00:17 +02006 * - sometimes record brokes playback with WSS portion of
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Yamaha OPL3-SA3 chip
8 * - CS4231 (GUS MAX) - still trouble with occasional noises
Krzysztof Helt7779f752008-07-31 21:03:41 +02009 * - broken initialization?
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/delay.h>
28#include <linux/pm.h>
29#include <linux/init.h>
30#include <linux/interrupt.h>
31#include <linux/slab.h>
32#include <linux/ioport.h>
33#include <sound/core.h>
Krzysztof Helt61ef19d2008-07-31 21:02:42 +020034#include <sound/wss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <sound/pcm_params.h>
Krzysztof Helt5664daa2008-07-31 21:08:32 +020036#include <sound/tlv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#include <asm/io.h>
39#include <asm/dma.h>
40#include <asm/irq.h>
41
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020042MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070043MODULE_DESCRIPTION("Routines for control of CS4231(A)/CS4232/InterWave & compatible chips");
44MODULE_LICENSE("GPL");
45
46#if 0
47#define SNDRV_DEBUG_MCE
48#endif
49
50/*
51 * Some variables
52 */
53
54static unsigned char freq_bits[14] = {
55 /* 5510 */ 0x00 | CS4231_XTAL2,
56 /* 6620 */ 0x0E | CS4231_XTAL2,
57 /* 8000 */ 0x00 | CS4231_XTAL1,
58 /* 9600 */ 0x0E | CS4231_XTAL1,
59 /* 11025 */ 0x02 | CS4231_XTAL2,
60 /* 16000 */ 0x02 | CS4231_XTAL1,
61 /* 18900 */ 0x04 | CS4231_XTAL2,
62 /* 22050 */ 0x06 | CS4231_XTAL2,
63 /* 27042 */ 0x04 | CS4231_XTAL1,
64 /* 32000 */ 0x06 | CS4231_XTAL1,
65 /* 33075 */ 0x0C | CS4231_XTAL2,
66 /* 37800 */ 0x08 | CS4231_XTAL2,
67 /* 44100 */ 0x0A | CS4231_XTAL2,
68 /* 48000 */ 0x0C | CS4231_XTAL1
69};
70
71static unsigned int rates[14] = {
72 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050,
73 27042, 32000, 33075, 37800, 44100, 48000
74};
75
Takashi Iwaiba2375a2005-11-17 14:30:42 +010076static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
Krzysztof Helt6c041b52007-09-06 15:03:59 +020077 .count = ARRAY_SIZE(rates),
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 .list = rates,
79 .mask = 0,
80};
81
Krzysztof Helt7779f752008-07-31 21:03:41 +020082static int snd_wss_xrate(struct snd_pcm_runtime *runtime)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Krzysztof Helt7779f752008-07-31 21:03:41 +020084 return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
85 &hw_constraints_rates);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Krzysztof Helt7779f752008-07-31 21:03:41 +020088static unsigned char snd_wss_original_image[32] =
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 0x00, /* 00/00 - lic */
91 0x00, /* 01/01 - ric */
92 0x9f, /* 02/02 - la1ic */
93 0x9f, /* 03/03 - ra1ic */
94 0x9f, /* 04/04 - la2ic */
95 0x9f, /* 05/05 - ra2ic */
96 0xbf, /* 06/06 - loc */
97 0xbf, /* 07/07 - roc */
98 0x20, /* 08/08 - pdfr */
99 CS4231_AUTOCALIB, /* 09/09 - ic */
100 0x00, /* 0a/10 - pc */
101 0x00, /* 0b/11 - ti */
102 CS4231_MODE2, /* 0c/12 - mi */
103 0xfc, /* 0d/13 - lbc */
104 0x00, /* 0e/14 - pbru */
105 0x00, /* 0f/15 - pbrl */
106 0x80, /* 10/16 - afei */
107 0x01, /* 11/17 - afeii */
108 0x9f, /* 12/18 - llic */
109 0x9f, /* 13/19 - rlic */
110 0x00, /* 14/20 - tlb */
111 0x00, /* 15/21 - thb */
112 0x00, /* 16/22 - la3mic/reserved */
113 0x00, /* 17/23 - ra3mic/reserved */
114 0x00, /* 18/24 - afs */
115 0x00, /* 19/25 - lamoc/version */
116 0xcf, /* 1a/26 - mioc */
117 0x00, /* 1b/27 - ramoc/reserved */
118 0x20, /* 1c/28 - cdfr */
119 0x00, /* 1d/29 - res4 */
120 0x00, /* 1e/30 - cbru */
121 0x00, /* 1f/31 - cbrl */
122};
123
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +0200124static unsigned char snd_opti93x_original_image[32] =
125{
126 0x00, /* 00/00 - l_mixout_outctrl */
127 0x00, /* 01/01 - r_mixout_outctrl */
128 0x88, /* 02/02 - l_cd_inctrl */
129 0x88, /* 03/03 - r_cd_inctrl */
130 0x88, /* 04/04 - l_a1/fm_inctrl */
131 0x88, /* 05/05 - r_a1/fm_inctrl */
132 0x80, /* 06/06 - l_dac_inctrl */
133 0x80, /* 07/07 - r_dac_inctrl */
134 0x00, /* 08/08 - ply_dataform_reg */
135 0x00, /* 09/09 - if_conf */
136 0x00, /* 0a/10 - pin_ctrl */
137 0x00, /* 0b/11 - err_init_reg */
138 0x0a, /* 0c/12 - id_reg */
139 0x00, /* 0d/13 - reserved */
140 0x00, /* 0e/14 - ply_upcount_reg */
141 0x00, /* 0f/15 - ply_lowcount_reg */
142 0x88, /* 10/16 - reserved/l_a1_inctrl */
143 0x88, /* 11/17 - reserved/r_a1_inctrl */
144 0x88, /* 12/18 - l_line_inctrl */
145 0x88, /* 13/19 - r_line_inctrl */
146 0x88, /* 14/20 - l_mic_inctrl */
147 0x88, /* 15/21 - r_mic_inctrl */
148 0x80, /* 16/22 - l_out_outctrl */
149 0x80, /* 17/23 - r_out_outctrl */
150 0x00, /* 18/24 - reserved */
151 0x00, /* 19/25 - reserved */
152 0x00, /* 1a/26 - reserved */
153 0x00, /* 1b/27 - reserved */
154 0x00, /* 1c/28 - cap_dataform_reg */
155 0x00, /* 1d/29 - reserved */
156 0x00, /* 1e/30 - cap_upcount_reg */
157 0x00 /* 1f/31 - cap_lowcount_reg */
158};
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160/*
161 * Basic I/O functions
162 */
163
Krzysztof Helt7779f752008-07-31 21:03:41 +0200164static inline void wss_outb(struct snd_wss *chip, u8 offset, u8 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 outb(val, chip->port + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
Krzysztof Helt7779f752008-07-31 21:03:41 +0200169static inline u8 wss_inb(struct snd_wss *chip, u8 offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return inb(chip->port + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Krzysztof Helt7779f752008-07-31 21:03:41 +0200174static void snd_wss_wait(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
176 int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 for (timeout = 250;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200179 timeout > 0 && (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 timeout--)
Krzysztof Helt9295aea2008-07-31 21:00:17 +0200181 udelay(100);
Krzysztof Helt6c041b52007-09-06 15:03:59 +0200182}
183
Krzysztof Helt7779f752008-07-31 21:03:41 +0200184static void snd_wss_outm(struct snd_wss *chip, unsigned char reg,
Krzysztof Helt6c041b52007-09-06 15:03:59 +0200185 unsigned char mask, unsigned char value)
186{
187 unsigned char tmp = (chip->image[reg] & mask) | value;
188
Krzysztof Helt7779f752008-07-31 21:03:41 +0200189 snd_wss_wait(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190#ifdef CONFIG_SND_DEBUG
Krzysztof Helt7779f752008-07-31 21:03:41 +0200191 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
193#endif
Krzysztof Helt6c041b52007-09-06 15:03:59 +0200194 chip->image[reg] = tmp;
195 if (!chip->calibrate_mute) {
Krzysztof Helt7779f752008-07-31 21:03:41 +0200196 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
Krzysztof Helt6c041b52007-09-06 15:03:59 +0200197 wmb();
Krzysztof Helt7779f752008-07-31 21:03:41 +0200198 wss_outb(chip, CS4231P(REG), tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 mb();
200 }
201}
202
Krzysztof Helt7779f752008-07-31 21:03:41 +0200203static void snd_wss_dout(struct snd_wss *chip, unsigned char reg,
204 unsigned char value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 int timeout;
207
208 for (timeout = 250;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200209 timeout > 0 && (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 timeout--)
Krzysztof Helt9295aea2008-07-31 21:00:17 +0200211 udelay(10);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200212 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
213 wss_outb(chip, CS4231P(REG), value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 mb();
215}
216
Krzysztof Helt7779f752008-07-31 21:03:41 +0200217void snd_wss_out(struct snd_wss *chip, unsigned char reg, unsigned char value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200219 snd_wss_wait(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#ifdef CONFIG_SND_DEBUG
Krzysztof Helt7779f752008-07-31 21:03:41 +0200221 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
223#endif
Krzysztof Helt7779f752008-07-31 21:03:41 +0200224 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
225 wss_outb(chip, CS4231P(REG), value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 chip->image[reg] = value;
227 mb();
Krzysztof Helt6c041b52007-09-06 15:03:59 +0200228 snd_printdd("codec out - reg 0x%x = 0x%x\n",
229 chip->mce_bit | reg, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230}
Krzysztof Helt7779f752008-07-31 21:03:41 +0200231EXPORT_SYMBOL(snd_wss_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Krzysztof Helt7779f752008-07-31 21:03:41 +0200233unsigned char snd_wss_in(struct snd_wss *chip, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200235 snd_wss_wait(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#ifdef CONFIG_SND_DEBUG
Krzysztof Helt7779f752008-07-31 21:03:41 +0200237 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 snd_printk("in: auto calibration time out - reg = 0x%x\n", reg);
239#endif
Krzysztof Helt7779f752008-07-31 21:03:41 +0200240 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 mb();
Krzysztof Helt7779f752008-07-31 21:03:41 +0200242 return wss_inb(chip, CS4231P(REG));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
Krzysztof Helt7779f752008-07-31 21:03:41 +0200244EXPORT_SYMBOL(snd_wss_in);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Krzysztof Helt7779f752008-07-31 21:03:41 +0200246void snd_cs4236_ext_out(struct snd_wss *chip, unsigned char reg,
247 unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200249 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
250 wss_outb(chip, CS4231P(REG),
251 reg | (chip->image[CS4236_EXT_REG] & 0x01));
252 wss_outb(chip, CS4231P(REG), val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 chip->eimage[CS4236_REG(reg)] = val;
254#if 0
255 printk("ext out : reg = 0x%x, val = 0x%x\n", reg, val);
256#endif
257}
Krzysztof Helt7779f752008-07-31 21:03:41 +0200258EXPORT_SYMBOL(snd_cs4236_ext_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Krzysztof Helt7779f752008-07-31 21:03:41 +0200260unsigned char snd_cs4236_ext_in(struct snd_wss *chip, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200262 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
263 wss_outb(chip, CS4231P(REG),
264 reg | (chip->image[CS4236_EXT_REG] & 0x01));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#if 1
Krzysztof Helt7779f752008-07-31 21:03:41 +0200266 return wss_inb(chip, CS4231P(REG));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#else
268 {
269 unsigned char res;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200270 res = wss_inb(chip, CS4231P(REG));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 printk("ext in : reg = 0x%x, val = 0x%x\n", reg, res);
272 return res;
273 }
274#endif
275}
Krzysztof Helt7779f752008-07-31 21:03:41 +0200276EXPORT_SYMBOL(snd_cs4236_ext_in);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
278#if 0
279
Krzysztof Helt7779f752008-07-31 21:03:41 +0200280static void snd_wss_debug(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200282 printk(KERN_DEBUG
283 "CS4231 REGS: INDEX = 0x%02x "
284 " STATUS = 0x%02x\n",
285 wss_inb(chip, CS4231P(REGSEL),
286 wss_inb(chip, CS4231P(STATUS)));
287 printk(KERN_DEBUG
288 " 0x00: left input = 0x%02x "
289 " 0x10: alt 1 (CFIG 2) = 0x%02x\n",
290 snd_wss_in(chip, 0x00),
291 snd_wss_in(chip, 0x10));
292 printk(KERN_DEBUG
293 " 0x01: right input = 0x%02x "
294 " 0x11: alt 2 (CFIG 3) = 0x%02x\n",
295 snd_wss_in(chip, 0x01),
296 snd_wss_in(chip, 0x11));
297 printk(KERN_DEBUG
298 " 0x02: GF1 left input = 0x%02x "
299 " 0x12: left line in = 0x%02x\n",
300 snd_wss_in(chip, 0x02),
301 snd_wss_in(chip, 0x12));
302 printk(KERN_DEBUG
303 " 0x03: GF1 right input = 0x%02x "
304 " 0x13: right line in = 0x%02x\n",
305 snd_wss_in(chip, 0x03),
306 snd_wss_in(chip, 0x13));
307 printk(KERN_DEBUG
308 " 0x04: CD left input = 0x%02x "
309 " 0x14: timer low = 0x%02x\n",
310 snd_wss_in(chip, 0x04),
311 snd_wss_in(chip, 0x14));
312 printk(KERN_DEBUG
313 " 0x05: CD right input = 0x%02x "
314 " 0x15: timer high = 0x%02x\n",
315 snd_wss_in(chip, 0x05),
316 snd_wss_in(chip, 0x15));
317 printk(KERN_DEBUG
318 " 0x06: left output = 0x%02x "
319 " 0x16: left MIC (PnP) = 0x%02x\n",
320 snd_wss_in(chip, 0x06),
321 snd_wss_in(chip, 0x16));
322 printk(KERN_DEBUG
323 " 0x07: right output = 0x%02x "
324 " 0x17: right MIC (PnP) = 0x%02x\n",
325 snd_wss_in(chip, 0x07),
326 snd_wss_in(chip, 0x17));
327 printk(KERN_DEBUG
328 " 0x08: playback format = 0x%02x "
329 " 0x18: IRQ status = 0x%02x\n",
330 snd_wss_in(chip, 0x08),
331 snd_wss_in(chip, 0x18));
332 printk(KERN_DEBUG
333 " 0x09: iface (CFIG 1) = 0x%02x "
334 " 0x19: left line out = 0x%02x\n",
335 snd_wss_in(chip, 0x09),
336 snd_wss_in(chip, 0x19));
337 printk(KERN_DEBUG
338 " 0x0a: pin control = 0x%02x "
339 " 0x1a: mono control = 0x%02x\n",
340 snd_wss_in(chip, 0x0a),
341 snd_wss_in(chip, 0x1a));
342 printk(KERN_DEBUG
343 " 0x0b: init & status = 0x%02x "
344 " 0x1b: right line out = 0x%02x\n",
345 snd_wss_in(chip, 0x0b),
346 snd_wss_in(chip, 0x1b));
347 printk(KERN_DEBUG
348 " 0x0c: revision & mode = 0x%02x "
349 " 0x1c: record format = 0x%02x\n",
350 snd_wss_in(chip, 0x0c),
351 snd_wss_in(chip, 0x1c));
352 printk(KERN_DEBUG
353 " 0x0d: loopback = 0x%02x "
354 " 0x1d: var freq (PnP) = 0x%02x\n",
355 snd_wss_in(chip, 0x0d),
356 snd_wss_in(chip, 0x1d));
357 printk(KERN_DEBUG
358 " 0x0e: ply upr count = 0x%02x "
359 " 0x1e: ply lwr count = 0x%02x\n",
360 snd_wss_in(chip, 0x0e),
361 snd_wss_in(chip, 0x1e));
362 printk(KERN_DEBUG
363 " 0x0f: rec upr count = 0x%02x "
364 " 0x1f: rec lwr count = 0x%02x\n",
365 snd_wss_in(chip, 0x0f),
366 snd_wss_in(chip, 0x1f));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367}
368
369#endif
370
371/*
372 * CS4231 detection / MCE routines
373 */
374
Krzysztof Helt7779f752008-07-31 21:03:41 +0200375static void snd_wss_busy_wait(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
377 int timeout;
378
379 /* huh.. looks like this sequence is proper for CS4231A chip (GUS MAX) */
380 for (timeout = 5; timeout > 0; timeout--)
Krzysztof Helt7779f752008-07-31 21:03:41 +0200381 wss_inb(chip, CS4231P(REGSEL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 /* end of cleanup sequence */
383 for (timeout = 250;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200384 timeout > 0 && (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 timeout--)
Krzysztof Helt9295aea2008-07-31 21:00:17 +0200386 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
388
Krzysztof Helt7779f752008-07-31 21:03:41 +0200389void snd_wss_mce_up(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
391 unsigned long flags;
392 int timeout;
393
Krzysztof Helt7779f752008-07-31 21:03:41 +0200394 snd_wss_wait(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#ifdef CONFIG_SND_DEBUG
Krzysztof Helt7779f752008-07-31 21:03:41 +0200396 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 snd_printk("mce_up - auto calibration time out (0)\n");
398#endif
399 spin_lock_irqsave(&chip->reg_lock, flags);
400 chip->mce_bit |= CS4231_MCE;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200401 timeout = wss_inb(chip, CS4231P(REGSEL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 if (timeout == 0x80)
403 snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
404 if (!(timeout & CS4231_MCE))
Krzysztof Helt7779f752008-07-31 21:03:41 +0200405 wss_outb(chip, CS4231P(REGSEL),
406 chip->mce_bit | (timeout & 0x1f));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 spin_unlock_irqrestore(&chip->reg_lock, flags);
408}
Krzysztof Helt7779f752008-07-31 21:03:41 +0200409EXPORT_SYMBOL(snd_wss_mce_up);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Krzysztof Helt7779f752008-07-31 21:03:41 +0200411void snd_wss_mce_down(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
413 unsigned long flags;
Takashi Iwaib875d652007-09-11 10:12:14 +0200414 unsigned long end_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 int timeout;
416
Krzysztof Helt7779f752008-07-31 21:03:41 +0200417 snd_wss_busy_wait(chip);
Rene Hermand44df2d2007-09-10 23:22:55 +0200418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#ifdef CONFIG_SND_DEBUG
Krzysztof Helt7779f752008-07-31 21:03:41 +0200420 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", (long)CS4231P(REGSEL));
422#endif
423 spin_lock_irqsave(&chip->reg_lock, flags);
424 chip->mce_bit &= ~CS4231_MCE;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200425 timeout = wss_inb(chip, CS4231P(REGSEL));
426 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 spin_unlock_irqrestore(&chip->reg_lock, flags);
428 if (timeout == 0x80)
429 snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
430 if ((timeout & CS4231_MCE) == 0 ||
Krzysztof Helt7779f752008-07-31 21:03:41 +0200431 !(chip->hardware & (WSS_HW_CS4231_MASK | WSS_HW_CS4232_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return;
433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Rene Herman90cf9b82007-09-10 23:19:55 +0200435 /*
436 * Wait for (possible -- during init auto-calibration may not be set)
437 * calibration process to start. Needs upto 5 sample periods on AD1848
438 * which at the slowest possible rate of 5.5125 kHz means 907 us.
439 */
440 msleep(1);
Rene Hermand44df2d2007-09-10 23:22:55 +0200441
442 snd_printdd("(1) jiffies = %lu\n", jiffies);
443
Krzysztof Helt23d4635ed2007-09-11 00:40:42 +0200444 /* check condition up to 250 ms */
Takashi Iwaib875d652007-09-11 10:12:14 +0200445 end_time = jiffies + msecs_to_jiffies(250);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200446 while (snd_wss_in(chip, CS4231_TEST_INIT) &
Krzysztof Helt23d4635ed2007-09-11 00:40:42 +0200447 CS4231_CALIB_IN_PROGRESS) {
448
Takashi Iwaib875d652007-09-11 10:12:14 +0200449 if (time_after(jiffies, end_time)) {
Krzysztof Helt23d4635ed2007-09-11 00:40:42 +0200450 snd_printk(KERN_ERR "mce_down - "
451 "auto calibration time out (2)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return;
453 }
Takashi Iwaib875d652007-09-11 10:12:14 +0200454 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
Rene Hermand44df2d2007-09-10 23:22:55 +0200456
457 snd_printdd("(2) jiffies = %lu\n", jiffies);
458
Krzysztof Helt23d4635ed2007-09-11 00:40:42 +0200459 /* check condition up to 100 ms */
Takashi Iwaib875d652007-09-11 10:12:14 +0200460 end_time = jiffies + msecs_to_jiffies(100);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200461 while (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) {
Takashi Iwaib875d652007-09-11 10:12:14 +0200462 if (time_after(jiffies, end_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
464 return;
465 }
Takashi Iwaib875d652007-09-11 10:12:14 +0200466 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
Rene Hermand44df2d2007-09-10 23:22:55 +0200468
469 snd_printdd("(3) jiffies = %lu\n", jiffies);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200470 snd_printd("mce_down - exit = 0x%x\n", wss_inb(chip, CS4231P(REGSEL)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471}
Krzysztof Helt7779f752008-07-31 21:03:41 +0200472EXPORT_SYMBOL(snd_wss_mce_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Krzysztof Helt7779f752008-07-31 21:03:41 +0200474static unsigned int snd_wss_get_count(unsigned char format, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
476 switch (format & 0xe0) {
477 case CS4231_LINEAR_16:
478 case CS4231_LINEAR_16_BIG:
479 size >>= 1;
480 break;
481 case CS4231_ADPCM_16:
482 return size >> 2;
483 }
484 if (format & CS4231_STEREO)
485 size >>= 1;
486 return size;
487}
488
Krzysztof Helt7779f752008-07-31 21:03:41 +0200489static int snd_wss_trigger(struct snd_pcm_substream *substream,
490 int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200492 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 int result = 0;
494 unsigned int what;
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100495 struct snd_pcm_substream *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 int do_start;
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 switch (cmd) {
499 case SNDRV_PCM_TRIGGER_START:
500 case SNDRV_PCM_TRIGGER_RESUME:
501 do_start = 1; break;
502 case SNDRV_PCM_TRIGGER_STOP:
503 case SNDRV_PCM_TRIGGER_SUSPEND:
504 do_start = 0; break;
505 default:
506 return -EINVAL;
507 }
508
509 what = 0;
Takashi Iwaief991b92007-02-22 12:52:53 +0100510 snd_pcm_group_for_each_entry(s, substream) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 if (s == chip->playback_substream) {
512 what |= CS4231_PLAYBACK_ENABLE;
513 snd_pcm_trigger_done(s, substream);
514 } else if (s == chip->capture_substream) {
515 what |= CS4231_RECORD_ENABLE;
516 snd_pcm_trigger_done(s, substream);
517 }
518 }
519 spin_lock(&chip->reg_lock);
520 if (do_start) {
521 chip->image[CS4231_IFACE_CTRL] |= what;
522 if (chip->trigger)
523 chip->trigger(chip, what, 1);
524 } else {
525 chip->image[CS4231_IFACE_CTRL] &= ~what;
526 if (chip->trigger)
527 chip->trigger(chip, what, 0);
528 }
Krzysztof Helt7779f752008-07-31 21:03:41 +0200529 snd_wss_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 spin_unlock(&chip->reg_lock);
531#if 0
Krzysztof Helt7779f752008-07-31 21:03:41 +0200532 snd_wss_debug(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#endif
534 return result;
535}
536
537/*
538 * CODEC I/O
539 */
540
Krzysztof Helt7779f752008-07-31 21:03:41 +0200541static unsigned char snd_wss_get_rate(unsigned int rate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
543 int i;
544
Krzysztof Helt6c041b52007-09-06 15:03:59 +0200545 for (i = 0; i < ARRAY_SIZE(rates); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 if (rate == rates[i])
547 return freq_bits[i];
548 // snd_BUG();
Krzysztof Helt6c041b52007-09-06 15:03:59 +0200549 return freq_bits[ARRAY_SIZE(rates) - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550}
551
Krzysztof Helt7779f752008-07-31 21:03:41 +0200552static unsigned char snd_wss_get_format(struct snd_wss *chip,
553 int format,
554 int channels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
556 unsigned char rformat;
557
558 rformat = CS4231_LINEAR_8;
559 switch (format) {
560 case SNDRV_PCM_FORMAT_MU_LAW: rformat = CS4231_ULAW_8; break;
561 case SNDRV_PCM_FORMAT_A_LAW: rformat = CS4231_ALAW_8; break;
562 case SNDRV_PCM_FORMAT_S16_LE: rformat = CS4231_LINEAR_16; break;
563 case SNDRV_PCM_FORMAT_S16_BE: rformat = CS4231_LINEAR_16_BIG; break;
564 case SNDRV_PCM_FORMAT_IMA_ADPCM: rformat = CS4231_ADPCM_16; break;
565 }
566 if (channels > 1)
567 rformat |= CS4231_STEREO;
568#if 0
569 snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode);
570#endif
571 return rformat;
572}
573
Krzysztof Helt7779f752008-07-31 21:03:41 +0200574static void snd_wss_calibrate_mute(struct snd_wss *chip, int mute)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575{
576 unsigned long flags;
577
578 mute = mute ? 1 : 0;
579 spin_lock_irqsave(&chip->reg_lock, flags);
580 if (chip->calibrate_mute == mute) {
581 spin_unlock_irqrestore(&chip->reg_lock, flags);
582 return;
583 }
584 if (!mute) {
Krzysztof Helt7779f752008-07-31 21:03:41 +0200585 snd_wss_dout(chip, CS4231_LEFT_INPUT,
586 chip->image[CS4231_LEFT_INPUT]);
587 snd_wss_dout(chip, CS4231_RIGHT_INPUT,
588 chip->image[CS4231_RIGHT_INPUT]);
589 snd_wss_dout(chip, CS4231_LOOPBACK,
590 chip->image[CS4231_LOOPBACK]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 }
Krzysztof Helt7779f752008-07-31 21:03:41 +0200592 snd_wss_dout(chip, CS4231_AUX1_LEFT_INPUT,
593 mute ? 0x80 : chip->image[CS4231_AUX1_LEFT_INPUT]);
594 snd_wss_dout(chip, CS4231_AUX1_RIGHT_INPUT,
595 mute ? 0x80 : chip->image[CS4231_AUX1_RIGHT_INPUT]);
596 snd_wss_dout(chip, CS4231_AUX2_LEFT_INPUT,
597 mute ? 0x80 : chip->image[CS4231_AUX2_LEFT_INPUT]);
598 snd_wss_dout(chip, CS4231_AUX2_RIGHT_INPUT,
599 mute ? 0x80 : chip->image[CS4231_AUX2_RIGHT_INPUT]);
600 snd_wss_dout(chip, CS4231_LEFT_OUTPUT,
601 mute ? 0x80 : chip->image[CS4231_LEFT_OUTPUT]);
602 snd_wss_dout(chip, CS4231_RIGHT_OUTPUT,
603 mute ? 0x80 : chip->image[CS4231_RIGHT_OUTPUT]);
604 snd_wss_dout(chip, CS4231_LEFT_LINE_IN,
605 mute ? 0x80 : chip->image[CS4231_LEFT_LINE_IN]);
606 snd_wss_dout(chip, CS4231_RIGHT_LINE_IN,
607 mute ? 0x80 : chip->image[CS4231_RIGHT_LINE_IN]);
608 snd_wss_dout(chip, CS4231_MONO_CTRL,
609 mute ? 0xc0 : chip->image[CS4231_MONO_CTRL]);
610 if (chip->hardware == WSS_HW_INTERWAVE) {
611 snd_wss_dout(chip, CS4231_LEFT_MIC_INPUT,
612 mute ? 0x80 : chip->image[CS4231_LEFT_MIC_INPUT]);
613 snd_wss_dout(chip, CS4231_RIGHT_MIC_INPUT,
614 mute ? 0x80 : chip->image[CS4231_RIGHT_MIC_INPUT]);
615 snd_wss_dout(chip, CS4231_LINE_LEFT_OUTPUT,
616 mute ? 0x80 : chip->image[CS4231_LINE_LEFT_OUTPUT]);
617 snd_wss_dout(chip, CS4231_LINE_RIGHT_OUTPUT,
618 mute ? 0x80 : chip->image[CS4231_LINE_RIGHT_OUTPUT]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
620 chip->calibrate_mute = mute;
621 spin_unlock_irqrestore(&chip->reg_lock, flags);
622}
623
Krzysztof Helt7779f752008-07-31 21:03:41 +0200624static void snd_wss_playback_format(struct snd_wss *chip,
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100625 struct snd_pcm_hw_params *params,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 unsigned char pdfr)
627{
628 unsigned long flags;
629 int full_calib = 1;
630
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100631 mutex_lock(&chip->mce_mutex);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200632 snd_wss_calibrate_mute(chip, 1);
633 if (chip->hardware == WSS_HW_CS4231A ||
634 (chip->hardware & WSS_HW_CS4232_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 spin_lock_irqsave(&chip->reg_lock, flags);
636 if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (pdfr & 0x0f)) { /* rate is same? */
Krzysztof Helt7779f752008-07-31 21:03:41 +0200637 snd_wss_out(chip, CS4231_ALT_FEATURE_1,
638 chip->image[CS4231_ALT_FEATURE_1] | 0x10);
639 chip->image[CS4231_PLAYBK_FORMAT] = pdfr;
640 snd_wss_out(chip, CS4231_PLAYBK_FORMAT,
641 chip->image[CS4231_PLAYBK_FORMAT]);
642 snd_wss_out(chip, CS4231_ALT_FEATURE_1,
643 chip->image[CS4231_ALT_FEATURE_1] &= ~0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 udelay(100); /* Fixes audible clicks at least on GUS MAX */
645 full_calib = 0;
646 }
647 spin_unlock_irqrestore(&chip->reg_lock, flags);
648 }
649 if (full_calib) {
Krzysztof Helt7779f752008-07-31 21:03:41 +0200650 snd_wss_mce_up(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200652 if (chip->hardware != WSS_HW_INTERWAVE && !chip->single_dma) {
653 if (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE)
654 pdfr = (pdfr & 0xf0) |
655 (chip->image[CS4231_REC_FORMAT] & 0x0f);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 } else {
Krzysztof Helt7779f752008-07-31 21:03:41 +0200657 chip->image[CS4231_PLAYBK_FORMAT] = pdfr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
Krzysztof Helt7779f752008-07-31 21:03:41 +0200659 snd_wss_out(chip, CS4231_PLAYBK_FORMAT, pdfr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200661 if (chip->hardware == WSS_HW_OPL3SA2)
Paul Vojtae2340462007-07-27 12:20:38 +0200662 udelay(100); /* this seems to help */
Krzysztof Helt7779f752008-07-31 21:03:41 +0200663 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 }
Krzysztof Helt7779f752008-07-31 21:03:41 +0200665 snd_wss_calibrate_mute(chip, 0);
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100666 mutex_unlock(&chip->mce_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667}
668
Krzysztof Helt7779f752008-07-31 21:03:41 +0200669static void snd_wss_capture_format(struct snd_wss *chip,
670 struct snd_pcm_hw_params *params,
671 unsigned char cdfr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
673 unsigned long flags;
674 int full_calib = 1;
675
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100676 mutex_lock(&chip->mce_mutex);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200677 snd_wss_calibrate_mute(chip, 1);
678 if (chip->hardware == WSS_HW_CS4231A ||
679 (chip->hardware & WSS_HW_CS4232_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 spin_lock_irqsave(&chip->reg_lock, flags);
681 if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (cdfr & 0x0f) || /* rate is same? */
682 (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) {
Krzysztof Helt7779f752008-07-31 21:03:41 +0200683 snd_wss_out(chip, CS4231_ALT_FEATURE_1,
684 chip->image[CS4231_ALT_FEATURE_1] | 0x20);
685 snd_wss_out(chip, CS4231_REC_FORMAT,
686 chip->image[CS4231_REC_FORMAT] = cdfr);
687 snd_wss_out(chip, CS4231_ALT_FEATURE_1,
688 chip->image[CS4231_ALT_FEATURE_1] &= ~0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 full_calib = 0;
690 }
691 spin_unlock_irqrestore(&chip->reg_lock, flags);
692 }
693 if (full_calib) {
Krzysztof Helt7779f752008-07-31 21:03:41 +0200694 snd_wss_mce_up(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200696 if (chip->hardware != WSS_HW_INTERWAVE &&
697 !(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) {
698 if (chip->single_dma)
699 snd_wss_out(chip, CS4231_PLAYBK_FORMAT, cdfr);
700 else
701 snd_wss_out(chip, CS4231_PLAYBK_FORMAT,
702 (chip->image[CS4231_PLAYBK_FORMAT] & 0xf0) |
703 (cdfr & 0x0f));
704 spin_unlock_irqrestore(&chip->reg_lock, flags);
705 snd_wss_mce_down(chip);
706 snd_wss_mce_up(chip);
707 spin_lock_irqsave(&chip->reg_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 }
Krzysztof Helt7779f752008-07-31 21:03:41 +0200709 snd_wss_out(chip, CS4231_REC_FORMAT, cdfr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200711 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
Krzysztof Helt7779f752008-07-31 21:03:41 +0200713 snd_wss_calibrate_mute(chip, 0);
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100714 mutex_unlock(&chip->mce_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715}
716
717/*
718 * Timer interface
719 */
720
Krzysztof Helt7779f752008-07-31 21:03:41 +0200721static unsigned long snd_wss_timer_resolution(struct snd_timer *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200723 struct snd_wss *chip = snd_timer_chip(timer);
724 if (chip->hardware & WSS_HW_CS4236B_MASK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 return 14467;
726 else
727 return chip->image[CS4231_PLAYBK_FORMAT] & 1 ? 9969 : 9920;
728}
729
Krzysztof Helt7779f752008-07-31 21:03:41 +0200730static int snd_wss_timer_start(struct snd_timer *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
732 unsigned long flags;
733 unsigned int ticks;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200734 struct snd_wss *chip = snd_timer_chip(timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 spin_lock_irqsave(&chip->reg_lock, flags);
736 ticks = timer->sticks;
737 if ((chip->image[CS4231_ALT_FEATURE_1] & CS4231_TIMER_ENABLE) == 0 ||
738 (unsigned char)(ticks >> 8) != chip->image[CS4231_TIMER_HIGH] ||
739 (unsigned char)ticks != chip->image[CS4231_TIMER_LOW]) {
Krzysztof Helt7779f752008-07-31 21:03:41 +0200740 chip->image[CS4231_TIMER_HIGH] = (unsigned char) (ticks >> 8);
741 snd_wss_out(chip, CS4231_TIMER_HIGH,
742 chip->image[CS4231_TIMER_HIGH]);
743 chip->image[CS4231_TIMER_LOW] = (unsigned char) ticks;
744 snd_wss_out(chip, CS4231_TIMER_LOW,
745 chip->image[CS4231_TIMER_LOW]);
746 snd_wss_out(chip, CS4231_ALT_FEATURE_1,
747 chip->image[CS4231_ALT_FEATURE_1] |
748 CS4231_TIMER_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 }
750 spin_unlock_irqrestore(&chip->reg_lock, flags);
751 return 0;
752}
753
Krzysztof Helt7779f752008-07-31 21:03:41 +0200754static int snd_wss_timer_stop(struct snd_timer *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
756 unsigned long flags;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200757 struct snd_wss *chip = snd_timer_chip(timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200759 chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE;
760 snd_wss_out(chip, CS4231_ALT_FEATURE_1,
761 chip->image[CS4231_ALT_FEATURE_1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 spin_unlock_irqrestore(&chip->reg_lock, flags);
763 return 0;
764}
765
Krzysztof Helt7779f752008-07-31 21:03:41 +0200766static void snd_wss_init(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
768 unsigned long flags;
769
Krzysztof Helt7779f752008-07-31 21:03:41 +0200770 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772#ifdef SNDRV_DEBUG_MCE
773 snd_printk("init: (1)\n");
774#endif
Krzysztof Helt7779f752008-07-31 21:03:41 +0200775 snd_wss_mce_up(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200777 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE |
778 CS4231_PLAYBACK_PIO |
779 CS4231_RECORD_ENABLE |
780 CS4231_RECORD_PIO |
781 CS4231_CALIB_MODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200783 snd_wss_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200785 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787#ifdef SNDRV_DEBUG_MCE
788 snd_printk("init: (2)\n");
789#endif
790
Krzysztof Helt7779f752008-07-31 21:03:41 +0200791 snd_wss_mce_up(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200793 snd_wss_out(chip,
794 CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200796 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798#ifdef SNDRV_DEBUG_MCE
Krzysztof Helt7779f752008-07-31 21:03:41 +0200799 snd_printk("init: (3) - afei = 0x%x\n",
800 chip->image[CS4231_ALT_FEATURE_1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801#endif
802
803 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200804 snd_wss_out(chip, CS4231_ALT_FEATURE_2,
805 chip->image[CS4231_ALT_FEATURE_2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 spin_unlock_irqrestore(&chip->reg_lock, flags);
807
Krzysztof Helt7779f752008-07-31 21:03:41 +0200808 snd_wss_mce_up(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200810 snd_wss_out(chip, CS4231_PLAYBK_FORMAT,
811 chip->image[CS4231_PLAYBK_FORMAT]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200813 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815#ifdef SNDRV_DEBUG_MCE
816 snd_printk("init: (4)\n");
817#endif
818
Krzysztof Helt7779f752008-07-31 21:03:41 +0200819 snd_wss_mce_up(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200821 snd_wss_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200823 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825#ifdef SNDRV_DEBUG_MCE
826 snd_printk("init: (5)\n");
827#endif
828}
829
Krzysztof Helt7779f752008-07-31 21:03:41 +0200830static int snd_wss_open(struct snd_wss *chip, unsigned int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
832 unsigned long flags;
833
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100834 mutex_lock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 if ((chip->mode & mode) ||
Krzysztof Helt7779f752008-07-31 21:03:41 +0200836 ((chip->mode & WSS_MODE_OPEN) && chip->single_dma)) {
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100837 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 return -EAGAIN;
839 }
Krzysztof Helt7779f752008-07-31 21:03:41 +0200840 if (chip->mode & WSS_MODE_OPEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 chip->mode |= mode;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100842 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 return 0;
844 }
845 /* ok. now enable and ack CODEC IRQ */
846 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200847 snd_wss_out(chip, CS4231_IRQ_STATUS,
848 CS4231_PLAYBACK_IRQ |
849 CS4231_RECORD_IRQ |
850 CS4231_TIMER_IRQ);
851 snd_wss_out(chip, CS4231_IRQ_STATUS, 0);
852 wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
853 wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 chip->image[CS4231_PIN_CTRL] |= CS4231_IRQ_ENABLE;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200855 snd_wss_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]);
856 snd_wss_out(chip, CS4231_IRQ_STATUS,
857 CS4231_PLAYBACK_IRQ |
858 CS4231_RECORD_IRQ |
859 CS4231_TIMER_IRQ);
860 snd_wss_out(chip, CS4231_IRQ_STATUS, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 spin_unlock_irqrestore(&chip->reg_lock, flags);
862
863 chip->mode = mode;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100864 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 return 0;
866}
867
Krzysztof Helt7779f752008-07-31 21:03:41 +0200868static void snd_wss_close(struct snd_wss *chip, unsigned int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
870 unsigned long flags;
871
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100872 mutex_lock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 chip->mode &= ~mode;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200874 if (chip->mode & WSS_MODE_OPEN) {
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100875 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 return;
877 }
Krzysztof Helt7779f752008-07-31 21:03:41 +0200878 snd_wss_calibrate_mute(chip, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 /* disable IRQ */
881 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200882 snd_wss_out(chip, CS4231_IRQ_STATUS, 0);
883 wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
884 wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 chip->image[CS4231_PIN_CTRL] &= ~CS4231_IRQ_ENABLE;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200886 snd_wss_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 /* now disable record & playback */
889
890 if (chip->image[CS4231_IFACE_CTRL] & (CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
891 CS4231_RECORD_ENABLE | CS4231_RECORD_PIO)) {
892 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200893 snd_wss_mce_up(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 spin_lock_irqsave(&chip->reg_lock, flags);
895 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO |
896 CS4231_RECORD_ENABLE | CS4231_RECORD_PIO);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200897 snd_wss_out(chip, CS4231_IFACE_CTRL,
898 chip->image[CS4231_IFACE_CTRL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200900 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 spin_lock_irqsave(&chip->reg_lock, flags);
902 }
903
904 /* clear IRQ again */
Krzysztof Helt7779f752008-07-31 21:03:41 +0200905 snd_wss_out(chip, CS4231_IRQ_STATUS, 0);
906 wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
907 wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 spin_unlock_irqrestore(&chip->reg_lock, flags);
909
Krzysztof Helt7779f752008-07-31 21:03:41 +0200910 snd_wss_calibrate_mute(chip, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 chip->mode = 0;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100913 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914}
915
916/*
917 * timer open/close
918 */
919
Krzysztof Helt7779f752008-07-31 21:03:41 +0200920static int snd_wss_timer_open(struct snd_timer *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200922 struct snd_wss *chip = snd_timer_chip(timer);
923 snd_wss_open(chip, WSS_MODE_TIMER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 return 0;
925}
926
Krzysztof Helt7779f752008-07-31 21:03:41 +0200927static int snd_wss_timer_close(struct snd_timer *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200929 struct snd_wss *chip = snd_timer_chip(timer);
930 snd_wss_close(chip, WSS_MODE_TIMER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 return 0;
932}
933
Krzysztof Helt7779f752008-07-31 21:03:41 +0200934static struct snd_timer_hardware snd_wss_timer_table =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
936 .flags = SNDRV_TIMER_HW_AUTO,
937 .resolution = 9945,
938 .ticks = 65535,
Krzysztof Helt7779f752008-07-31 21:03:41 +0200939 .open = snd_wss_timer_open,
940 .close = snd_wss_timer_close,
941 .c_resolution = snd_wss_timer_resolution,
942 .start = snd_wss_timer_start,
943 .stop = snd_wss_timer_stop,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944};
945
946/*
947 * ok.. exported functions..
948 */
949
Krzysztof Helt7779f752008-07-31 21:03:41 +0200950static int snd_wss_playback_hw_params(struct snd_pcm_substream *substream,
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100951 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200953 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 unsigned char new_pdfr;
955 int err;
956
957 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
958 return err;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200959 new_pdfr = snd_wss_get_format(chip, params_format(hw_params),
960 params_channels(hw_params)) |
961 snd_wss_get_rate(params_rate(hw_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 chip->set_playback_format(chip, hw_params, new_pdfr);
963 return 0;
964}
965
Krzysztof Helt7779f752008-07-31 21:03:41 +0200966static int snd_wss_playback_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
968 return snd_pcm_lib_free_pages(substream);
969}
970
Krzysztof Helt7779f752008-07-31 21:03:41 +0200971static int snd_wss_playback_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200973 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100974 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 unsigned long flags;
976 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
977 unsigned int count = snd_pcm_lib_period_bytes(substream);
978
979 spin_lock_irqsave(&chip->reg_lock, flags);
980 chip->p_dma_size = size;
981 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO);
982 snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
Krzysztof Helt7779f752008-07-31 21:03:41 +0200983 count = snd_wss_get_count(chip->image[CS4231_PLAYBK_FORMAT], count) - 1;
984 snd_wss_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count);
985 snd_wss_out(chip, CS4231_PLY_UPR_CNT, (unsigned char) (count >> 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 spin_unlock_irqrestore(&chip->reg_lock, flags);
987#if 0
Krzysztof Helt7779f752008-07-31 21:03:41 +0200988 snd_wss_debug(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989#endif
990 return 0;
991}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
Krzysztof Helt7779f752008-07-31 21:03:41 +0200993static int snd_wss_capture_hw_params(struct snd_pcm_substream *substream,
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100994 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
Krzysztof Helt7779f752008-07-31 21:03:41 +0200996 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 unsigned char new_cdfr;
998 int err;
999
1000 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
1001 return err;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001002 new_cdfr = snd_wss_get_format(chip, params_format(hw_params),
1003 params_channels(hw_params)) |
1004 snd_wss_get_rate(params_rate(hw_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 chip->set_capture_format(chip, hw_params, new_cdfr);
1006 return 0;
1007}
1008
Krzysztof Helt7779f752008-07-31 21:03:41 +02001009static int snd_wss_capture_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
1011 return snd_pcm_lib_free_pages(substream);
1012}
1013
Krzysztof Helt7779f752008-07-31 21:03:41 +02001014static int snd_wss_capture_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001016 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Takashi Iwaiba2375a2005-11-17 14:30:42 +01001017 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 unsigned long flags;
1019 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
1020 unsigned int count = snd_pcm_lib_period_bytes(substream);
1021
1022 spin_lock_irqsave(&chip->reg_lock, flags);
1023 chip->c_dma_size = size;
1024 chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE | CS4231_RECORD_PIO);
1025 snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001026 count = snd_wss_get_count(chip->image[CS4231_REC_FORMAT], count) - 1;
1027 if (chip->single_dma && chip->hardware != WSS_HW_INTERWAVE) {
1028 snd_wss_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count);
1029 snd_wss_out(chip, CS4231_PLY_UPR_CNT,
1030 (unsigned char) (count >> 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 } else {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001032 snd_wss_out(chip, CS4231_REC_LWR_CNT, (unsigned char) count);
1033 snd_wss_out(chip, CS4231_REC_UPR_CNT,
1034 (unsigned char) (count >> 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
1036 spin_unlock_irqrestore(&chip->reg_lock, flags);
1037 return 0;
1038}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Krzysztof Helt7779f752008-07-31 21:03:41 +02001040void snd_wss_overrange(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
1042 unsigned long flags;
1043 unsigned char res;
1044
1045 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001046 res = snd_wss_in(chip, CS4231_TEST_INIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 spin_unlock_irqrestore(&chip->reg_lock, flags);
1048 if (res & (0x08 | 0x02)) /* detect overrange only above 0dB; may be user selectable? */
1049 chip->capture_substream->runtime->overrange++;
1050}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001051EXPORT_SYMBOL(snd_wss_overrange);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Krzysztof Helt7779f752008-07-31 21:03:41 +02001053irqreturn_t snd_wss_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001055 struct snd_wss *chip = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 unsigned char status;
1057
Krzysztof Helt7779f752008-07-31 21:03:41 +02001058 status = snd_wss_in(chip, CS4231_IRQ_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 if (status & CS4231_TIMER_IRQ) {
1060 if (chip->timer)
1061 snd_timer_interrupt(chip->timer, chip->timer->sticks);
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001062 }
Krzysztof Helt7779f752008-07-31 21:03:41 +02001063 if (chip->single_dma && chip->hardware != WSS_HW_INTERWAVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 if (status & CS4231_PLAYBACK_IRQ) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001065 if (chip->mode & WSS_MODE_PLAY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 if (chip->playback_substream)
1067 snd_pcm_period_elapsed(chip->playback_substream);
1068 }
Krzysztof Helt7779f752008-07-31 21:03:41 +02001069 if (chip->mode & WSS_MODE_RECORD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 if (chip->capture_substream) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001071 snd_wss_overrange(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 snd_pcm_period_elapsed(chip->capture_substream);
1073 }
1074 }
1075 }
1076 } else {
1077 if (status & CS4231_PLAYBACK_IRQ) {
1078 if (chip->playback_substream)
1079 snd_pcm_period_elapsed(chip->playback_substream);
1080 }
1081 if (status & CS4231_RECORD_IRQ) {
1082 if (chip->capture_substream) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001083 snd_wss_overrange(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 snd_pcm_period_elapsed(chip->capture_substream);
1085 }
1086 }
1087 }
1088
1089 spin_lock(&chip->reg_lock);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001090 snd_wss_outm(chip, CS4231_IRQ_STATUS, ~CS4231_ALL_IRQS | ~status, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 spin_unlock(&chip->reg_lock);
1092 return IRQ_HANDLED;
1093}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001094EXPORT_SYMBOL(snd_wss_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Krzysztof Helt7779f752008-07-31 21:03:41 +02001096static snd_pcm_uframes_t snd_wss_playback_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001098 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 size_t ptr;
1100
1101 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE))
1102 return 0;
1103 ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
1104 return bytes_to_frames(substream->runtime, ptr);
1105}
1106
Krzysztof Helt7779f752008-07-31 21:03:41 +02001107static snd_pcm_uframes_t snd_wss_capture_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001109 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 size_t ptr;
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE))
1113 return 0;
1114 ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
1115 return bytes_to_frames(substream->runtime, ptr);
1116}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118/*
1119
1120 */
1121
Krzysztof Helt7779f752008-07-31 21:03:41 +02001122static int snd_wss_probe(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
1124 unsigned long flags;
1125 int i, id, rev;
1126 unsigned char *ptr;
1127 unsigned int hw;
1128
1129#if 0
Krzysztof Helt7779f752008-07-31 21:03:41 +02001130 snd_wss_debug(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131#endif
1132 id = 0;
1133 for (i = 0; i < 50; i++) {
1134 mb();
Krzysztof Helt7779f752008-07-31 21:03:41 +02001135 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 udelay(2000);
1137 else {
1138 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001139 snd_wss_out(chip, CS4231_MISC_INFO, CS4231_MODE2);
1140 id = snd_wss_in(chip, CS4231_MISC_INFO) & 0x0f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 spin_unlock_irqrestore(&chip->reg_lock, flags);
1142 if (id == 0x0a)
1143 break; /* this is valid value */
1144 }
1145 }
Krzysztof Helt7779f752008-07-31 21:03:41 +02001146 snd_printdd("wss: port = 0x%lx, id = 0x%x\n", chip->port, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 if (id != 0x0a)
1148 return -ENODEV; /* no valid device found */
1149
Krzysztof Helt7779f752008-07-31 21:03:41 +02001150 hw = chip->hardware;
1151 if ((hw & WSS_HW_TYPE_MASK) == WSS_HW_DETECT) {
1152 rev = snd_wss_in(chip, CS4231_VERSION) & 0xe7;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 snd_printdd("CS4231: VERSION (I25) = 0x%x\n", rev);
1154 if (rev == 0x80) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001155 unsigned char tmp = snd_wss_in(chip, 23);
1156 snd_wss_out(chip, 23, ~tmp);
1157 if (snd_wss_in(chip, 23) != tmp)
1158 chip->hardware = WSS_HW_AD1845;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 else
Krzysztof Helt7779f752008-07-31 21:03:41 +02001160 chip->hardware = WSS_HW_CS4231;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 } else if (rev == 0xa0) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001162 chip->hardware = WSS_HW_CS4231A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 } else if (rev == 0xa2) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001164 chip->hardware = WSS_HW_CS4232;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 } else if (rev == 0xb2) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001166 chip->hardware = WSS_HW_CS4232A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 } else if (rev == 0x83) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001168 chip->hardware = WSS_HW_CS4236;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 } else if (rev == 0x03) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001170 chip->hardware = WSS_HW_CS4236B;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 } else {
1172 snd_printk("unknown CS chip with version 0x%x\n", rev);
1173 return -ENODEV; /* unknown CS4231 chip? */
1174 }
1175 }
1176 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001177 wss_inb(chip, CS4231P(STATUS)); /* clear any pendings IRQ */
1178 wss_outb(chip, CS4231P(STATUS), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 mb();
1180 spin_unlock_irqrestore(&chip->reg_lock, flags);
1181
1182 chip->image[CS4231_MISC_INFO] = CS4231_MODE2;
1183 switch (chip->hardware) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001184 case WSS_HW_INTERWAVE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 chip->image[CS4231_MISC_INFO] = CS4231_IW_MODE3;
1186 break;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001187 case WSS_HW_CS4235:
1188 case WSS_HW_CS4236B:
1189 case WSS_HW_CS4237B:
1190 case WSS_HW_CS4238B:
1191 case WSS_HW_CS4239:
1192 if (hw == WSS_HW_DETECT3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 chip->image[CS4231_MISC_INFO] = CS4231_4236_MODE3;
1194 else
Krzysztof Helt7779f752008-07-31 21:03:41 +02001195 chip->hardware = WSS_HW_CS4236;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 break;
1197 }
1198
1199 chip->image[CS4231_IFACE_CTRL] =
1200 (chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA) |
1201 (chip->single_dma ? CS4231_SINGLE_DMA : 0);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001202 if (chip->hardware != WSS_HW_OPTI93X) {
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02001203 chip->image[CS4231_ALT_FEATURE_1] = 0x80;
1204 chip->image[CS4231_ALT_FEATURE_2] =
Krzysztof Helt7779f752008-07-31 21:03:41 +02001205 chip->hardware == WSS_HW_INTERWAVE ? 0xc2 : 0x01;
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02001206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 ptr = (unsigned char *) &chip->image;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001208 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 spin_lock_irqsave(&chip->reg_lock, flags);
1210 for (i = 0; i < 32; i++) /* ok.. fill all CS4231 registers */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001211 snd_wss_out(chip, i, *ptr++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001213 snd_wss_mce_up(chip);
1214 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
1216 mdelay(2);
1217
1218 /* ok.. try check hardware version for CS4236+ chips */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001219 if ((hw & WSS_HW_TYPE_MASK) == WSS_HW_DETECT) {
1220 if (chip->hardware == WSS_HW_CS4236B) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 rev = snd_cs4236_ext_in(chip, CS4236_VERSION);
1222 snd_cs4236_ext_out(chip, CS4236_VERSION, 0xff);
1223 id = snd_cs4236_ext_in(chip, CS4236_VERSION);
1224 snd_cs4236_ext_out(chip, CS4236_VERSION, rev);
1225 snd_printdd("CS4231: ext version; rev = 0x%x, id = 0x%x\n", rev, id);
1226 if ((id & 0x1f) == 0x1d) { /* CS4235 */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001227 chip->hardware = WSS_HW_CS4235;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 switch (id >> 5) {
1229 case 4:
1230 case 5:
1231 case 6:
1232 break;
1233 default:
1234 snd_printk("unknown CS4235 chip (enhanced version = 0x%x)\n", id);
1235 }
1236 } else if ((id & 0x1f) == 0x0b) { /* CS4236/B */
1237 switch (id >> 5) {
1238 case 4:
1239 case 5:
1240 case 6:
1241 case 7:
Krzysztof Helt7779f752008-07-31 21:03:41 +02001242 chip->hardware = WSS_HW_CS4236B;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 break;
1244 default:
1245 snd_printk("unknown CS4236 chip (enhanced version = 0x%x)\n", id);
1246 }
1247 } else if ((id & 0x1f) == 0x08) { /* CS4237B */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001248 chip->hardware = WSS_HW_CS4237B;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 switch (id >> 5) {
1250 case 4:
1251 case 5:
1252 case 6:
1253 case 7:
1254 break;
1255 default:
1256 snd_printk("unknown CS4237B chip (enhanced version = 0x%x)\n", id);
1257 }
1258 } else if ((id & 0x1f) == 0x09) { /* CS4238B */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001259 chip->hardware = WSS_HW_CS4238B;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 switch (id >> 5) {
1261 case 5:
1262 case 6:
1263 case 7:
1264 break;
1265 default:
1266 snd_printk("unknown CS4238B chip (enhanced version = 0x%x)\n", id);
1267 }
1268 } else if ((id & 0x1f) == 0x1e) { /* CS4239 */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001269 chip->hardware = WSS_HW_CS4239;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 switch (id >> 5) {
1271 case 4:
1272 case 5:
1273 case 6:
1274 break;
1275 default:
1276 snd_printk("unknown CS4239 chip (enhanced version = 0x%x)\n", id);
1277 }
1278 } else {
1279 snd_printk("unknown CS4236/CS423xB chip (enhanced version = 0x%x)\n", id);
1280 }
1281 }
1282 }
1283 return 0; /* all things are ok.. */
1284}
1285
1286/*
1287
1288 */
1289
Krzysztof Helt7779f752008-07-31 21:03:41 +02001290static struct snd_pcm_hardware snd_wss_playback =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291{
1292 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1293 SNDRV_PCM_INFO_MMAP_VALID |
1294 SNDRV_PCM_INFO_RESUME |
1295 SNDRV_PCM_INFO_SYNC_START),
1296 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
1297 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
1298 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
1299 .rate_min = 5510,
1300 .rate_max = 48000,
1301 .channels_min = 1,
1302 .channels_max = 2,
1303 .buffer_bytes_max = (128*1024),
1304 .period_bytes_min = 64,
1305 .period_bytes_max = (128*1024),
1306 .periods_min = 1,
1307 .periods_max = 1024,
1308 .fifo_size = 0,
1309};
1310
Krzysztof Helt7779f752008-07-31 21:03:41 +02001311static struct snd_pcm_hardware snd_wss_capture =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312{
1313 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
1314 SNDRV_PCM_INFO_MMAP_VALID |
1315 SNDRV_PCM_INFO_RESUME |
1316 SNDRV_PCM_INFO_SYNC_START),
1317 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM |
1318 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE),
1319 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
1320 .rate_min = 5510,
1321 .rate_max = 48000,
1322 .channels_min = 1,
1323 .channels_max = 2,
1324 .buffer_bytes_max = (128*1024),
1325 .period_bytes_min = 64,
1326 .period_bytes_max = (128*1024),
1327 .periods_min = 1,
1328 .periods_max = 1024,
1329 .fifo_size = 0,
1330};
1331
1332/*
1333
1334 */
1335
Krzysztof Helt7779f752008-07-31 21:03:41 +02001336static int snd_wss_playback_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001338 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Takashi Iwaiba2375a2005-11-17 14:30:42 +01001339 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 int err;
1341
Krzysztof Helt7779f752008-07-31 21:03:41 +02001342 runtime->hw = snd_wss_playback;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 /* hardware bug in InterWave chipset */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001345 if (chip->hardware == WSS_HW_INTERWAVE && chip->dma1 > 3)
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001346 runtime->hw.formats &= ~SNDRV_PCM_FMTBIT_MU_LAW;
1347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 /* hardware limitation of cheap chips */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001349 if (chip->hardware == WSS_HW_CS4235 ||
1350 chip->hardware == WSS_HW_CS4239)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
1352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
1354 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max);
1355
1356 if (chip->claim_dma) {
1357 if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma1)) < 0)
1358 return err;
1359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Krzysztof Helt7779f752008-07-31 21:03:41 +02001361 err = snd_wss_open(chip, WSS_MODE_PLAY);
1362 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 if (chip->release_dma)
1364 chip->release_dma(chip, chip->dma_private_data, chip->dma1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 snd_free_pages(runtime->dma_area, runtime->dma_bytes);
1366 return err;
1367 }
1368 chip->playback_substream = substream;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 snd_pcm_set_sync(substream);
1370 chip->rate_constraint(runtime);
1371 return 0;
1372}
1373
Krzysztof Helt7779f752008-07-31 21:03:41 +02001374static int snd_wss_capture_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001376 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Takashi Iwaiba2375a2005-11-17 14:30:42 +01001377 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 int err;
1379
Krzysztof Helt7779f752008-07-31 21:03:41 +02001380 runtime->hw = snd_wss_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 /* hardware limitation of cheap chips */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001383 if (chip->hardware == WSS_HW_CS4235 ||
1384 chip->hardware == WSS_HW_CS4239)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
1386
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
1388 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max);
1389
1390 if (chip->claim_dma) {
1391 if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma2)) < 0)
1392 return err;
1393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Krzysztof Helt7779f752008-07-31 21:03:41 +02001395 err = snd_wss_open(chip, WSS_MODE_RECORD);
1396 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 if (chip->release_dma)
1398 chip->release_dma(chip, chip->dma_private_data, chip->dma2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 snd_free_pages(runtime->dma_area, runtime->dma_bytes);
1400 return err;
1401 }
1402 chip->capture_substream = substream;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 snd_pcm_set_sync(substream);
1404 chip->rate_constraint(runtime);
1405 return 0;
1406}
1407
Krzysztof Helt7779f752008-07-31 21:03:41 +02001408static int snd_wss_playback_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001410 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
1412 chip->playback_substream = NULL;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001413 snd_wss_close(chip, WSS_MODE_PLAY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 return 0;
1415}
1416
Krzysztof Helt7779f752008-07-31 21:03:41 +02001417static int snd_wss_capture_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001419 struct snd_wss *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
1421 chip->capture_substream = NULL;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001422 snd_wss_close(chip, WSS_MODE_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 return 0;
1424}
1425
1426#ifdef CONFIG_PM
1427
1428/* lowlevel suspend callback for CS4231 */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001429static void snd_wss_suspend(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430{
1431 int reg;
1432 unsigned long flags;
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001433
Takashi Iwai7bb35e202005-11-17 17:00:17 +01001434 snd_pcm_suspend_all(chip->pcm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 spin_lock_irqsave(&chip->reg_lock, flags);
1436 for (reg = 0; reg < 32; reg++)
Krzysztof Helt7779f752008-07-31 21:03:41 +02001437 chip->image[reg] = snd_wss_in(chip, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 spin_unlock_irqrestore(&chip->reg_lock, flags);
1439}
1440
1441/* lowlevel resume callback for CS4231 */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001442static void snd_wss_resume(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443{
1444 int reg;
1445 unsigned long flags;
Takashi Iwaia2c855b2005-11-18 18:52:39 +01001446 /* int timeout; */
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001447
Krzysztof Helt7779f752008-07-31 21:03:41 +02001448 snd_wss_mce_up(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 spin_lock_irqsave(&chip->reg_lock, flags);
1450 for (reg = 0; reg < 32; reg++) {
1451 switch (reg) {
1452 case CS4231_VERSION:
1453 break;
1454 default:
Krzysztof Helt7779f752008-07-31 21:03:41 +02001455 snd_wss_out(chip, reg, chip->image[reg]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 break;
1457 }
1458 }
1459 spin_unlock_irqrestore(&chip->reg_lock, flags);
Takashi Iwaifa55f832005-11-17 17:48:30 +01001460#if 1
Krzysztof Helt7779f752008-07-31 21:03:41 +02001461 snd_wss_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462#else
1463 /* The following is a workaround to avoid freeze after resume on TP600E.
Krzysztof Helt7779f752008-07-31 21:03:41 +02001464 This is the first half of copy of snd_wss_mce_down(), but doesn't
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 include rescheduling. -- iwai
1466 */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001467 snd_wss_busy_wait(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 spin_lock_irqsave(&chip->reg_lock, flags);
1469 chip->mce_bit &= ~CS4231_MCE;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001470 timeout = wss_inb(chip, CS4231P(REGSEL));
1471 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 spin_unlock_irqrestore(&chip->reg_lock, flags);
1473 if (timeout == 0x80)
1474 snd_printk("down [0x%lx]: serious init problem - codec still busy\n", chip->port);
1475 if ((timeout & CS4231_MCE) == 0 ||
Krzysztof Helt7779f752008-07-31 21:03:41 +02001476 !(chip->hardware & (WSS_HW_CS4231_MASK | WSS_HW_CS4232_MASK))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 return;
1478 }
Krzysztof Helt7779f752008-07-31 21:03:41 +02001479 snd_wss_busy_wait(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480#endif
1481}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482#endif /* CONFIG_PM */
1483
Krzysztof Helt7779f752008-07-31 21:03:41 +02001484static int snd_wss_free(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
Takashi Iwaib1d57762005-10-10 11:56:31 +02001486 release_and_free_resource(chip->res_port);
1487 release_and_free_resource(chip->res_cport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 if (chip->irq >= 0) {
1489 disable_irq(chip->irq);
Krzysztof Helt7779f752008-07-31 21:03:41 +02001490 if (!(chip->hwshare & WSS_HWSHARE_IRQ))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 free_irq(chip->irq, (void *) chip);
1492 }
Krzysztof Helt7779f752008-07-31 21:03:41 +02001493 if (!(chip->hwshare & WSS_HWSHARE_DMA1) && chip->dma1 >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 snd_dma_disable(chip->dma1);
1495 free_dma(chip->dma1);
1496 }
Krzysztof Helt7779f752008-07-31 21:03:41 +02001497 if (!(chip->hwshare & WSS_HWSHARE_DMA2) &&
1498 chip->dma2 >= 0 && chip->dma2 != chip->dma1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 snd_dma_disable(chip->dma2);
1500 free_dma(chip->dma2);
1501 }
1502 if (chip->timer)
1503 snd_device_free(chip->card, chip->timer);
1504 kfree(chip);
1505 return 0;
1506}
1507
Krzysztof Helt7779f752008-07-31 21:03:41 +02001508static int snd_wss_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001510 struct snd_wss *chip = device->device_data;
1511 return snd_wss_free(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512}
1513
Krzysztof Helt7779f752008-07-31 21:03:41 +02001514const char *snd_wss_chip_id(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
1516 switch (chip->hardware) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001517 case WSS_HW_CS4231:
1518 return "CS4231";
1519 case WSS_HW_CS4231A:
1520 return "CS4231A";
1521 case WSS_HW_CS4232:
1522 return "CS4232";
1523 case WSS_HW_CS4232A:
1524 return "CS4232A";
1525 case WSS_HW_CS4235:
1526 return "CS4235";
1527 case WSS_HW_CS4236:
1528 return "CS4236";
1529 case WSS_HW_CS4236B:
1530 return "CS4236B";
1531 case WSS_HW_CS4237B:
1532 return "CS4237B";
1533 case WSS_HW_CS4238B:
1534 return "CS4238B";
1535 case WSS_HW_CS4239:
1536 return "CS4239";
1537 case WSS_HW_INTERWAVE:
1538 return "AMD InterWave";
1539 case WSS_HW_OPL3SA2:
1540 return chip->card->shortname;
1541 case WSS_HW_AD1845:
1542 return "AD1845";
1543 case WSS_HW_OPTI93X:
1544 return "OPTi 93x";
1545 default:
1546 return "???";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 }
1548}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001549EXPORT_SYMBOL(snd_wss_chip_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Krzysztof Helt7779f752008-07-31 21:03:41 +02001551static int snd_wss_new(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 unsigned short hardware,
1553 unsigned short hwshare,
Krzysztof Helt7779f752008-07-31 21:03:41 +02001554 struct snd_wss **rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001556 struct snd_wss *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 *rchip = NULL;
Takashi Iwai9e76a762005-09-09 14:21:17 +02001559 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 if (chip == NULL)
1561 return -ENOMEM;
1562 chip->hardware = hardware;
1563 chip->hwshare = hwshare;
1564
1565 spin_lock_init(&chip->reg_lock);
Ingo Molnar8b7547f2006-01-16 16:33:08 +01001566 mutex_init(&chip->mce_mutex);
1567 mutex_init(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 chip->card = card;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001569 chip->rate_constraint = snd_wss_xrate;
1570 chip->set_playback_format = snd_wss_playback_format;
1571 chip->set_capture_format = snd_wss_capture_format;
1572 if (chip->hardware == WSS_HW_OPTI93X)
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02001573 memcpy(&chip->image, &snd_opti93x_original_image,
1574 sizeof(snd_opti93x_original_image));
1575 else
Krzysztof Helt7779f752008-07-31 21:03:41 +02001576 memcpy(&chip->image, &snd_wss_original_image,
1577 sizeof(snd_wss_original_image));
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02001578
Krzysztof Helt7779f752008-07-31 21:03:41 +02001579 *rchip = chip;
1580 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581}
1582
Krzysztof Helt7779f752008-07-31 21:03:41 +02001583int snd_wss_create(struct snd_card *card,
1584 unsigned long port,
1585 unsigned long cport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 int irq, int dma1, int dma2,
1587 unsigned short hardware,
1588 unsigned short hwshare,
Krzysztof Helt7779f752008-07-31 21:03:41 +02001589 struct snd_wss **rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590{
Takashi Iwaiba2375a2005-11-17 14:30:42 +01001591 static struct snd_device_ops ops = {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001592 .dev_free = snd_wss_dev_free,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 };
Krzysztof Helt7779f752008-07-31 21:03:41 +02001594 struct snd_wss *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 int err;
1596
Krzysztof Helt7779f752008-07-31 21:03:41 +02001597 err = snd_wss_new(card, hardware, hwshare, &chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 if (err < 0)
1599 return err;
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 chip->irq = -1;
1602 chip->dma1 = -1;
1603 chip->dma2 = -1;
1604
Krzysztof Helt7779f752008-07-31 21:03:41 +02001605 chip->res_port = request_region(port, 4, "CS4231");
1606 if (!chip->res_port) {
1607 snd_printk(KERN_ERR "wss: can't grab port 0x%lx\n", port);
1608 snd_wss_free(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 return -EBUSY;
1610 }
1611 chip->port = port;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001612 if ((long)cport >= 0) {
1613 chip->res_cport = request_region(cport, 8, "CS4232 Control");
1614 if (!chip->res_cport) {
1615 snd_printk(KERN_ERR
1616 "wss: can't grab control port 0x%lx\n", cport);
1617 snd_wss_free(chip);
1618 return -ENODEV;
1619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 }
1621 chip->cport = cport;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001622 if (!(hwshare & WSS_HWSHARE_IRQ))
1623 if (request_irq(irq, snd_wss_interrupt, IRQF_DISABLED,
1624 "CS4231", (void *) chip)) {
1625 snd_printk(KERN_ERR "wss: can't grab IRQ %d\n", irq);
1626 snd_wss_free(chip);
1627 return -EBUSY;
1628 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 chip->irq = irq;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001630 if (!(hwshare & WSS_HWSHARE_DMA1) && request_dma(dma1, "CS4231 - 1")) {
1631 snd_printk(KERN_ERR "wss: can't grab DMA1 %d\n", dma1);
1632 snd_wss_free(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 return -EBUSY;
1634 }
1635 chip->dma1 = dma1;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001636 if (!(hwshare & WSS_HWSHARE_DMA2) && dma1 != dma2 &&
1637 dma2 >= 0 && request_dma(dma2, "CS4231 - 2")) {
1638 snd_printk(KERN_ERR "wss: can't grab DMA2 %d\n", dma2);
1639 snd_wss_free(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 return -EBUSY;
1641 }
1642 if (dma1 == dma2 || dma2 < 0) {
1643 chip->single_dma = 1;
1644 chip->dma2 = chip->dma1;
1645 } else
1646 chip->dma2 = dma2;
1647
1648 /* global setup */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001649 if (snd_wss_probe(chip) < 0) {
1650 snd_wss_free(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 return -ENODEV;
1652 }
Krzysztof Helt7779f752008-07-31 21:03:41 +02001653 snd_wss_init(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
Takashi Iwaia9824c82005-11-17 17:51:00 +01001655#if 0
Krzysztof Helt7779f752008-07-31 21:03:41 +02001656 if (chip->hardware & WSS_HW_CS4232_MASK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 if (chip->res_cport == NULL)
1658 snd_printk("CS4232 control port features are not accessible\n");
1659 }
Takashi Iwaia9824c82005-11-17 17:51:00 +01001660#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
1662 /* Register device */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001663 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1664 if (err < 0) {
1665 snd_wss_free(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 return err;
1667 }
1668
1669#ifdef CONFIG_PM
1670 /* Power Management */
Krzysztof Helt7779f752008-07-31 21:03:41 +02001671 chip->suspend = snd_wss_suspend;
1672 chip->resume = snd_wss_resume;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673#endif
1674
1675 *rchip = chip;
1676 return 0;
1677}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001678EXPORT_SYMBOL(snd_wss_create);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Krzysztof Helt7779f752008-07-31 21:03:41 +02001680static struct snd_pcm_ops snd_wss_playback_ops = {
1681 .open = snd_wss_playback_open,
1682 .close = snd_wss_playback_close,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 .ioctl = snd_pcm_lib_ioctl,
Krzysztof Helt7779f752008-07-31 21:03:41 +02001684 .hw_params = snd_wss_playback_hw_params,
1685 .hw_free = snd_wss_playback_hw_free,
1686 .prepare = snd_wss_playback_prepare,
1687 .trigger = snd_wss_trigger,
1688 .pointer = snd_wss_playback_pointer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689};
1690
Krzysztof Helt7779f752008-07-31 21:03:41 +02001691static struct snd_pcm_ops snd_wss_capture_ops = {
1692 .open = snd_wss_capture_open,
1693 .close = snd_wss_capture_close,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 .ioctl = snd_pcm_lib_ioctl,
Krzysztof Helt7779f752008-07-31 21:03:41 +02001695 .hw_params = snd_wss_capture_hw_params,
1696 .hw_free = snd_wss_capture_hw_free,
1697 .prepare = snd_wss_capture_prepare,
1698 .trigger = snd_wss_trigger,
1699 .pointer = snd_wss_capture_pointer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700};
1701
Krzysztof Helt7779f752008-07-31 21:03:41 +02001702int snd_wss_pcm(struct snd_wss *chip, int device, struct snd_pcm **rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703{
Takashi Iwaiba2375a2005-11-17 14:30:42 +01001704 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 int err;
1706
1707 if ((err = snd_pcm_new(chip->card, "CS4231", device, 1, 1, &pcm)) < 0)
1708 return err;
1709
1710 spin_lock_init(&chip->reg_lock);
Ingo Molnar8b7547f2006-01-16 16:33:08 +01001711 mutex_init(&chip->mce_mutex);
1712 mutex_init(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
Krzysztof Helt7779f752008-07-31 21:03:41 +02001714 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_wss_playback_ops);
1715 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_wss_capture_ops);
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001716
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 /* global setup */
1718 pcm->private_data = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 pcm->info_flags = 0;
1720 if (chip->single_dma)
1721 pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001722 if (chip->hardware != WSS_HW_INTERWAVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001724 strcpy(pcm->name, snd_wss_chip_id(chip));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1727 snd_dma_isa_data(),
1728 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
1730 chip->pcm = pcm;
1731 if (rpcm)
1732 *rpcm = pcm;
1733 return 0;
1734}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001735EXPORT_SYMBOL(snd_wss_pcm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
Krzysztof Helt7779f752008-07-31 21:03:41 +02001737static void snd_wss_timer_free(struct snd_timer *timer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001739 struct snd_wss *chip = timer->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 chip->timer = NULL;
1741}
1742
Krzysztof Helt7779f752008-07-31 21:03:41 +02001743int snd_wss_timer(struct snd_wss *chip, int device, struct snd_timer **rtimer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744{
Takashi Iwaiba2375a2005-11-17 14:30:42 +01001745 struct snd_timer *timer;
1746 struct snd_timer_id tid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 int err;
1748
1749 /* Timer initialization */
1750 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
1751 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
1752 tid.card = chip->card->number;
1753 tid.device = device;
1754 tid.subdevice = 0;
1755 if ((err = snd_timer_new(chip->card, "CS4231", &tid, &timer)) < 0)
1756 return err;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001757 strcpy(timer->name, snd_wss_chip_id(chip));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 timer->private_data = chip;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001759 timer->private_free = snd_wss_timer_free;
1760 timer->hw = snd_wss_timer_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 chip->timer = timer;
1762 if (rtimer)
1763 *rtimer = timer;
1764 return 0;
1765}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001766EXPORT_SYMBOL(snd_wss_timer);
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768/*
1769 * MIXER part
1770 */
1771
Krzysztof Helt7779f752008-07-31 21:03:41 +02001772static int snd_wss_info_mux(struct snd_kcontrol *kcontrol,
1773 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
1775 static char *texts[4] = {
1776 "Line", "Aux", "Mic", "Mix"
1777 };
1778 static char *opl3sa_texts[4] = {
1779 "Line", "CD", "Mic", "Mix"
1780 };
1781 static char *gusmax_texts[4] = {
1782 "Line", "Synth", "Mic", "Mix"
1783 };
1784 char **ptexts = texts;
Krzysztof Helt7779f752008-07-31 21:03:41 +02001785 struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
1787 snd_assert(chip->card != NULL, return -EINVAL);
1788 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1789 uinfo->count = 2;
1790 uinfo->value.enumerated.items = 4;
1791 if (uinfo->value.enumerated.item > 3)
1792 uinfo->value.enumerated.item = 3;
1793 if (!strcmp(chip->card->driver, "GUS MAX"))
1794 ptexts = gusmax_texts;
1795 switch (chip->hardware) {
Krzysztof Helt7779f752008-07-31 21:03:41 +02001796 case WSS_HW_INTERWAVE:
1797 ptexts = gusmax_texts;
1798 break;
1799 case WSS_HW_OPL3SA2:
1800 ptexts = opl3sa_texts;
1801 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 }
1803 strcpy(uinfo->value.enumerated.name, ptexts[uinfo->value.enumerated.item]);
1804 return 0;
1805}
1806
Krzysztof Helt7779f752008-07-31 21:03:41 +02001807static int snd_wss_get_mux(struct snd_kcontrol *kcontrol,
1808 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001810 struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 unsigned long flags;
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001812
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 spin_lock_irqsave(&chip->reg_lock, flags);
1814 ucontrol->value.enumerated.item[0] = (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6;
1815 ucontrol->value.enumerated.item[1] = (chip->image[CS4231_RIGHT_INPUT] & CS4231_MIXS_ALL) >> 6;
1816 spin_unlock_irqrestore(&chip->reg_lock, flags);
1817 return 0;
1818}
1819
Krzysztof Helt7779f752008-07-31 21:03:41 +02001820static int snd_wss_put_mux(struct snd_kcontrol *kcontrol,
1821 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001823 struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 unsigned long flags;
1825 unsigned short left, right;
1826 int change;
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001827
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 if (ucontrol->value.enumerated.item[0] > 3 ||
1829 ucontrol->value.enumerated.item[1] > 3)
1830 return -EINVAL;
1831 left = ucontrol->value.enumerated.item[0] << 6;
1832 right = ucontrol->value.enumerated.item[1] << 6;
1833 spin_lock_irqsave(&chip->reg_lock, flags);
1834 left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left;
1835 right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right;
1836 change = left != chip->image[CS4231_LEFT_INPUT] ||
Krzysztof Helt7779f752008-07-31 21:03:41 +02001837 right != chip->image[CS4231_RIGHT_INPUT];
1838 snd_wss_out(chip, CS4231_LEFT_INPUT, left);
1839 snd_wss_out(chip, CS4231_RIGHT_INPUT, right);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 spin_unlock_irqrestore(&chip->reg_lock, flags);
1841 return change;
1842}
1843
Krzysztof Helt7779f752008-07-31 21:03:41 +02001844int snd_wss_info_single(struct snd_kcontrol *kcontrol,
1845 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846{
1847 int mask = (kcontrol->private_value >> 16) & 0xff;
1848
1849 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1850 uinfo->count = 1;
1851 uinfo->value.integer.min = 0;
1852 uinfo->value.integer.max = mask;
1853 return 0;
1854}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001855EXPORT_SYMBOL(snd_wss_info_single);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Krzysztof Helt7779f752008-07-31 21:03:41 +02001857int snd_wss_get_single(struct snd_kcontrol *kcontrol,
1858 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001860 struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 unsigned long flags;
1862 int reg = kcontrol->private_value & 0xff;
1863 int shift = (kcontrol->private_value >> 8) & 0xff;
1864 int mask = (kcontrol->private_value >> 16) & 0xff;
1865 int invert = (kcontrol->private_value >> 24) & 0xff;
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001866
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 spin_lock_irqsave(&chip->reg_lock, flags);
1868 ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
1869 spin_unlock_irqrestore(&chip->reg_lock, flags);
1870 if (invert)
1871 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1872 return 0;
1873}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001874EXPORT_SYMBOL(snd_wss_get_single);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
Krzysztof Helt7779f752008-07-31 21:03:41 +02001876int snd_wss_put_single(struct snd_kcontrol *kcontrol,
1877 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001879 struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 unsigned long flags;
1881 int reg = kcontrol->private_value & 0xff;
1882 int shift = (kcontrol->private_value >> 8) & 0xff;
1883 int mask = (kcontrol->private_value >> 16) & 0xff;
1884 int invert = (kcontrol->private_value >> 24) & 0xff;
1885 int change;
1886 unsigned short val;
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001887
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 val = (ucontrol->value.integer.value[0] & mask);
1889 if (invert)
1890 val = mask - val;
1891 val <<= shift;
1892 spin_lock_irqsave(&chip->reg_lock, flags);
1893 val = (chip->image[reg] & ~(mask << shift)) | val;
1894 change = val != chip->image[reg];
Krzysztof Helt7779f752008-07-31 21:03:41 +02001895 snd_wss_out(chip, reg, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 spin_unlock_irqrestore(&chip->reg_lock, flags);
1897 return change;
1898}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001899EXPORT_SYMBOL(snd_wss_put_single);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Krzysztof Helt7779f752008-07-31 21:03:41 +02001901int snd_wss_info_double(struct snd_kcontrol *kcontrol,
1902 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903{
1904 int mask = (kcontrol->private_value >> 24) & 0xff;
1905
1906 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1907 uinfo->count = 2;
1908 uinfo->value.integer.min = 0;
1909 uinfo->value.integer.max = mask;
1910 return 0;
1911}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001912EXPORT_SYMBOL(snd_wss_info_double);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Krzysztof Helt7779f752008-07-31 21:03:41 +02001914int snd_wss_get_double(struct snd_kcontrol *kcontrol,
1915 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001917 struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 unsigned long flags;
1919 int left_reg = kcontrol->private_value & 0xff;
1920 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1921 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1922 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1923 int mask = (kcontrol->private_value >> 24) & 0xff;
1924 int invert = (kcontrol->private_value >> 22) & 1;
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001925
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 spin_lock_irqsave(&chip->reg_lock, flags);
1927 ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
1928 ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
1929 spin_unlock_irqrestore(&chip->reg_lock, flags);
1930 if (invert) {
1931 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1932 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1933 }
1934 return 0;
1935}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001936EXPORT_SYMBOL(snd_wss_get_double);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
Krzysztof Helt7779f752008-07-31 21:03:41 +02001938int snd_wss_put_double(struct snd_kcontrol *kcontrol,
1939 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940{
Krzysztof Helt7779f752008-07-31 21:03:41 +02001941 struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 unsigned long flags;
1943 int left_reg = kcontrol->private_value & 0xff;
1944 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1945 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1946 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1947 int mask = (kcontrol->private_value >> 24) & 0xff;
1948 int invert = (kcontrol->private_value >> 22) & 1;
1949 int change;
1950 unsigned short val1, val2;
Krzysztof Helt9295aea2008-07-31 21:00:17 +02001951
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 val1 = ucontrol->value.integer.value[0] & mask;
1953 val2 = ucontrol->value.integer.value[1] & mask;
1954 if (invert) {
1955 val1 = mask - val1;
1956 val2 = mask - val2;
1957 }
1958 val1 <<= shift_left;
1959 val2 <<= shift_right;
1960 spin_lock_irqsave(&chip->reg_lock, flags);
Krzysztof Helt5664daa2008-07-31 21:08:32 +02001961 if (left_reg != right_reg) {
1962 val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
1963 val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
1964 change = val1 != chip->image[left_reg] ||
1965 val2 != chip->image[right_reg];
1966 snd_wss_out(chip, left_reg, val1);
1967 snd_wss_out(chip, right_reg, val2);
1968 } else {
1969 mask = (mask << shift_left) | (mask << shift_right);
1970 val1 = (chip->image[left_reg] & ~mask) | val1 | val2;
1971 change = val1 != chip->image[left_reg];
1972 snd_wss_out(chip, left_reg, val1);
1973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 spin_unlock_irqrestore(&chip->reg_lock, flags);
1975 return change;
1976}
Krzysztof Helt7779f752008-07-31 21:03:41 +02001977EXPORT_SYMBOL(snd_wss_put_double);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
Krzysztof Helt5664daa2008-07-31 21:08:32 +02001979static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
1980static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
1981static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
1982
1983static struct snd_kcontrol_new snd_ad1848_controls[] = {
1984WSS_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT,
1985 7, 7, 1, 1),
1986WSS_DOUBLE_TLV("PCM Playback Volume", 0,
1987 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1,
1988 db_scale_6bit),
1989WSS_DOUBLE("Aux Playback Switch", 0,
1990 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
1991WSS_DOUBLE_TLV("Aux Playback Volume", 0,
1992 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
1993 db_scale_5bit_12db_max),
1994WSS_DOUBLE("Aux Playback Switch", 1,
1995 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
1996WSS_DOUBLE_TLV("Aux Playback Volume", 1,
1997 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
1998 db_scale_5bit_12db_max),
1999WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT,
2000 0, 0, 15, 0, db_scale_rec_gain),
2001{
2002 .name = "Capture Source",
2003 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2004 .info = snd_wss_info_mux,
2005 .get = snd_wss_get_mux,
2006 .put = snd_wss_put_mux,
2007},
2008WSS_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
2009WSS_SINGLE_TLV("Loopback Capture Volume", 0, CS4231_LOOPBACK, 1, 63, 0,
2010 db_scale_6bit),
2011};
2012
Krzysztof Helt7779f752008-07-31 21:03:41 +02002013static struct snd_kcontrol_new snd_wss_controls[] = {
2014WSS_DOUBLE("PCM Playback Switch", 0,
2015 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
2016WSS_DOUBLE("PCM Playback Volume", 0,
2017 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
2018WSS_DOUBLE("Line Playback Switch", 0,
2019 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
2020WSS_DOUBLE("Line Playback Volume", 0,
2021 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1),
2022WSS_DOUBLE("Aux Playback Switch", 0,
2023 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
2024WSS_DOUBLE("Aux Playback Volume", 0,
2025 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
2026WSS_DOUBLE("Aux Playback Switch", 1,
2027 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
2028WSS_DOUBLE("Aux Playback Volume", 1,
2029 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
2030WSS_SINGLE("Mono Playback Switch", 0,
2031 CS4231_MONO_CTRL, 7, 1, 1),
2032WSS_SINGLE("Mono Playback Volume", 0,
2033 CS4231_MONO_CTRL, 0, 15, 1),
2034WSS_SINGLE("Mono Output Playback Switch", 0,
2035 CS4231_MONO_CTRL, 6, 1, 1),
2036WSS_SINGLE("Mono Output Playback Bypass", 0,
2037 CS4231_MONO_CTRL, 5, 1, 0),
2038WSS_DOUBLE("Capture Volume", 0,
2039 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
2041 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2042 .name = "Capture Source",
Krzysztof Helt7779f752008-07-31 21:03:41 +02002043 .info = snd_wss_info_mux,
2044 .get = snd_wss_get_mux,
2045 .put = snd_wss_put_mux,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046},
Krzysztof Helt7779f752008-07-31 21:03:41 +02002047WSS_DOUBLE("Mic Boost", 0,
2048 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
2049WSS_SINGLE("Loopback Capture Switch", 0,
2050 CS4231_LOOPBACK, 0, 1, 0),
2051WSS_SINGLE("Loopback Capture Volume", 0,
2052 CS4231_LOOPBACK, 2, 63, 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053};
Krzysztof Helt9295aea2008-07-31 21:00:17 +02002054
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02002055static struct snd_kcontrol_new snd_opti93x_controls[] = {
Krzysztof Helt7779f752008-07-31 21:03:41 +02002056WSS_DOUBLE("Master Playback Switch", 0,
2057 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
2058WSS_DOUBLE("Master Playback Volume", 0,
2059 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1),
2060WSS_DOUBLE("PCM Playback Switch", 0,
2061 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
2062WSS_DOUBLE("PCM Playback Volume", 0,
2063 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1),
2064WSS_DOUBLE("FM Playback Switch", 0,
2065 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
2066WSS_DOUBLE("FM Playback Volume", 0,
2067 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1),
2068WSS_DOUBLE("Line Playback Switch", 0,
2069 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
2070WSS_DOUBLE("Line Playback Volume", 0,
2071 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1),
2072WSS_DOUBLE("Mic Playback Switch", 0,
2073 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
2074WSS_DOUBLE("Mic Playback Volume", 0,
2075 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1),
2076WSS_DOUBLE("Mic Boost", 0,
2077 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
2078WSS_DOUBLE("CD Playback Switch", 0,
2079 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
2080WSS_DOUBLE("CD Playback Volume", 0,
2081 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1),
2082WSS_DOUBLE("Aux Playback Switch", 0,
2083 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
2084WSS_DOUBLE("Aux Playback Volume", 0,
2085 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1),
2086WSS_DOUBLE("Capture Volume", 0,
2087 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02002088{
2089 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2090 .name = "Capture Source",
Krzysztof Helt7779f752008-07-31 21:03:41 +02002091 .info = snd_wss_info_mux,
2092 .get = snd_wss_get_mux,
2093 .put = snd_wss_put_mux,
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02002094}
2095};
2096
Krzysztof Helt7779f752008-07-31 21:03:41 +02002097int snd_wss_mixer(struct snd_wss *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098{
Takashi Iwaiba2375a2005-11-17 14:30:42 +01002099 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 unsigned int idx;
2101 int err;
2102
2103 snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL);
2104
2105 card = chip->card;
2106
2107 strcpy(card->mixername, chip->pcm->name);
2108
Krzysztof Helt7779f752008-07-31 21:03:41 +02002109 if (chip->hardware == WSS_HW_OPTI93X)
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02002110 for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
2111 err = snd_ctl_add(card,
2112 snd_ctl_new1(&snd_opti93x_controls[idx],
2113 chip));
2114 if (err < 0)
2115 return err;
2116 }
Krzysztof Helt5664daa2008-07-31 21:08:32 +02002117 else if (chip->hardware & WSS_HW_AD1848_MASK)
2118 for (idx = 0; idx < ARRAY_SIZE(snd_ad1848_controls); idx++) {
2119 err = snd_ctl_add(card,
2120 snd_ctl_new1(&snd_ad1848_controls[idx],
2121 chip));
2122 if (err < 0)
2123 return err;
2124 }
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02002125 else
Krzysztof Helt7779f752008-07-31 21:03:41 +02002126 for (idx = 0; idx < ARRAY_SIZE(snd_wss_controls); idx++) {
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02002127 err = snd_ctl_add(card,
Krzysztof Helt7779f752008-07-31 21:03:41 +02002128 snd_ctl_new1(&snd_wss_controls[idx],
Krzysztof Heltabf1f5a2008-06-09 23:07:28 +02002129 chip));
2130 if (err < 0)
2131 return err;
2132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 return 0;
2134}
Krzysztof Helt7779f752008-07-31 21:03:41 +02002135EXPORT_SYMBOL(snd_wss_mixer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
2137/*
2138 * INIT part
2139 */
2140
Krzysztof Helt7779f752008-07-31 21:03:41 +02002141static int __init alsa_wss_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142{
2143 return 0;
2144}
2145
Krzysztof Helt7779f752008-07-31 21:03:41 +02002146static void __exit alsa_wss_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147{
2148}
2149
Krzysztof Helt7779f752008-07-31 21:03:41 +02002150module_init(alsa_wss_init);
2151module_exit(alsa_wss_exit);