diff options
Diffstat (limited to 'sound/sparc/cs4231.c')
-rw-r--r-- | sound/sparc/cs4231.c | 805 |
1 files changed, 354 insertions, 451 deletions
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c index f2950cab74a6..9785382a5f39 100644 --- a/sound/sparc/cs4231.c +++ b/sound/sparc/cs4231.c | |||
@@ -3,9 +3,9 @@ | |||
3 | * Copyright (C) 2002 David S. Miller <davem@redhat.com> | 3 | * Copyright (C) 2002 David S. Miller <davem@redhat.com> |
4 | * | 4 | * |
5 | * Based entirely upon drivers/sbus/audio/cs4231.c which is: | 5 | * Based entirely upon drivers/sbus/audio/cs4231.c which is: |
6 | * Copyright (C) 1996, 1997, 1998, 1998 Derrick J Brashear (shadow@andrew.cmu.edu) | 6 | * Copyright (C) 1996, 1997, 1998 Derrick J Brashear (shadow@andrew.cmu.edu) |
7 | * and also sound/isa/cs423x/cs4231_lib.c which is: | 7 | * and also sound/isa/cs423x/cs4231_lib.c which is: |
8 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> | 8 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/module.h> | 11 | #include <linux/module.h> |
@@ -15,6 +15,9 @@ | |||
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
17 | #include <linux/moduleparam.h> | 17 | #include <linux/moduleparam.h> |
18 | #include <linux/irq.h> | ||
19 | #include <linux/io.h> | ||
20 | |||
18 | 21 | ||
19 | #include <sound/driver.h> | 22 | #include <sound/driver.h> |
20 | #include <sound/core.h> | 23 | #include <sound/core.h> |
@@ -25,29 +28,21 @@ | |||
25 | #include <sound/initval.h> | 28 | #include <sound/initval.h> |
26 | #include <sound/pcm_params.h> | 29 | #include <sound/pcm_params.h> |
27 | 30 | ||
28 | #include <asm/io.h> | ||
29 | #include <asm/irq.h> | ||
30 | |||
31 | #ifdef CONFIG_SBUS | 31 | #ifdef CONFIG_SBUS |
32 | #define SBUS_SUPPORT | 32 | #define SBUS_SUPPORT |
33 | #endif | ||
34 | |||
35 | #ifdef SBUS_SUPPORT | ||
36 | #include <asm/sbus.h> | 33 | #include <asm/sbus.h> |
37 | #endif | 34 | #endif |
38 | 35 | ||
39 | #if defined(CONFIG_PCI) && defined(CONFIG_SPARC64) | 36 | #if defined(CONFIG_PCI) && defined(CONFIG_SPARC64) |
40 | #define EBUS_SUPPORT | 37 | #define EBUS_SUPPORT |
41 | #endif | ||
42 | |||
43 | #ifdef EBUS_SUPPORT | ||
44 | #include <linux/pci.h> | 38 | #include <linux/pci.h> |
45 | #include <asm/ebus.h> | 39 | #include <asm/ebus.h> |
46 | #endif | 40 | #endif |
47 | 41 | ||
48 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ | 42 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
49 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ | 43 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
50 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ | 44 | /* Enable this card */ |
45 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; | ||
51 | 46 | ||
52 | module_param_array(index, int, NULL, 0444); | 47 | module_param_array(index, int, NULL, 0444); |
53 | MODULE_PARM_DESC(index, "Index value for Sun CS4231 soundcard."); | 48 | MODULE_PARM_DESC(index, "Index value for Sun CS4231 soundcard."); |
@@ -62,19 +57,22 @@ MODULE_SUPPORTED_DEVICE("{{Sun,CS4231}}"); | |||
62 | 57 | ||
63 | #ifdef SBUS_SUPPORT | 58 | #ifdef SBUS_SUPPORT |
64 | struct sbus_dma_info { | 59 | struct sbus_dma_info { |
65 | spinlock_t lock; | 60 | spinlock_t lock; /* DMA access lock */ |
66 | int dir; | 61 | int dir; |
67 | void __iomem *regs; | 62 | void __iomem *regs; |
68 | }; | 63 | }; |
69 | #endif | 64 | #endif |
70 | 65 | ||
71 | struct snd_cs4231; | 66 | struct snd_cs4231; |
72 | struct cs4231_dma_control { | 67 | struct cs4231_dma_control { |
73 | void (*prepare)(struct cs4231_dma_control *dma_cont, int dir); | 68 | void (*prepare)(struct cs4231_dma_control *dma_cont, |
74 | void (*enable)(struct cs4231_dma_control *dma_cont, int on); | 69 | int dir); |
75 | int (*request)(struct cs4231_dma_control *dma_cont, dma_addr_t bus_addr, size_t len); | 70 | void (*enable)(struct cs4231_dma_control *dma_cont, int on); |
76 | unsigned int (*address)(struct cs4231_dma_control *dma_cont); | 71 | int (*request)(struct cs4231_dma_control *dma_cont, |
77 | void (*preallocate)(struct snd_cs4231 *chip, struct snd_pcm *pcm); | 72 | dma_addr_t bus_addr, size_t len); |
73 | unsigned int (*address)(struct cs4231_dma_control *dma_cont); | ||
74 | void (*preallocate)(struct snd_cs4231 *chip, | ||
75 | struct snd_pcm *pcm); | ||
78 | #ifdef EBUS_SUPPORT | 76 | #ifdef EBUS_SUPPORT |
79 | struct ebus_dma_info ebus_info; | 77 | struct ebus_dma_info ebus_info; |
80 | #endif | 78 | #endif |
@@ -84,7 +82,7 @@ struct cs4231_dma_control { | |||
84 | }; | 82 | }; |
85 | 83 | ||
86 | struct snd_cs4231 { | 84 | struct snd_cs4231 { |
87 | spinlock_t lock; | 85 | spinlock_t lock; /* registers access lock */ |
88 | void __iomem *port; | 86 | void __iomem *port; |
89 | 87 | ||
90 | struct cs4231_dma_control p_dma; | 88 | struct cs4231_dma_control p_dma; |
@@ -108,13 +106,14 @@ struct snd_cs4231 { | |||
108 | #define CS4231_MODE_PLAY 0x0001 | 106 | #define CS4231_MODE_PLAY 0x0001 |
109 | #define CS4231_MODE_RECORD 0x0002 | 107 | #define CS4231_MODE_RECORD 0x0002 |
110 | #define CS4231_MODE_TIMER 0x0004 | 108 | #define CS4231_MODE_TIMER 0x0004 |
111 | #define CS4231_MODE_OPEN (CS4231_MODE_PLAY|CS4231_MODE_RECORD|CS4231_MODE_TIMER) | 109 | #define CS4231_MODE_OPEN (CS4231_MODE_PLAY | CS4231_MODE_RECORD | \ |
110 | CS4231_MODE_TIMER) | ||
112 | 111 | ||
113 | unsigned char image[32]; /* registers image */ | 112 | unsigned char image[32]; /* registers image */ |
114 | int mce_bit; | 113 | int mce_bit; |
115 | int calibrate_mute; | 114 | int calibrate_mute; |
116 | struct mutex mce_mutex; | 115 | struct mutex mce_mutex; /* mutex for mce register */ |
117 | struct mutex open_mutex; | 116 | struct mutex open_mutex; /* mutex for ALSA open/close */ |
118 | 117 | ||
119 | union { | 118 | union { |
120 | #ifdef SBUS_SUPPORT | 119 | #ifdef SBUS_SUPPORT |
@@ -136,129 +135,10 @@ static struct snd_cs4231 *cs4231_list; | |||
136 | */ | 135 | */ |
137 | 136 | ||
138 | /* IO ports */ | 137 | /* IO ports */ |
139 | 138 | #include <sound/cs4231-regs.h> | |
140 | #define CS4231P(chip, x) ((chip)->port + c_d_c_CS4231##x) | ||
141 | 139 | ||
142 | /* XXX offsets are different than PC ISA chips... */ | 140 | /* XXX offsets are different than PC ISA chips... */ |
143 | #define c_d_c_CS4231REGSEL 0x0 | 141 | #define CS4231U(chip, x) ((chip)->port + ((c_d_c_CS4231##x) << 2)) |
144 | #define c_d_c_CS4231REG 0x4 | ||
145 | #define c_d_c_CS4231STATUS 0x8 | ||
146 | #define c_d_c_CS4231PIO 0xc | ||
147 | |||
148 | /* codec registers */ | ||
149 | |||
150 | #define CS4231_LEFT_INPUT 0x00 /* left input control */ | ||
151 | #define CS4231_RIGHT_INPUT 0x01 /* right input control */ | ||
152 | #define CS4231_AUX1_LEFT_INPUT 0x02 /* left AUX1 input control */ | ||
153 | #define CS4231_AUX1_RIGHT_INPUT 0x03 /* right AUX1 input control */ | ||
154 | #define CS4231_AUX2_LEFT_INPUT 0x04 /* left AUX2 input control */ | ||
155 | #define CS4231_AUX2_RIGHT_INPUT 0x05 /* right AUX2 input control */ | ||
156 | #define CS4231_LEFT_OUTPUT 0x06 /* left output control register */ | ||
157 | #define CS4231_RIGHT_OUTPUT 0x07 /* right output control register */ | ||
158 | #define CS4231_PLAYBK_FORMAT 0x08 /* clock and data format - playback - bits 7-0 MCE */ | ||
159 | #define CS4231_IFACE_CTRL 0x09 /* interface control - bits 7-2 MCE */ | ||
160 | #define CS4231_PIN_CTRL 0x0a /* pin control */ | ||
161 | #define CS4231_TEST_INIT 0x0b /* test and initialization */ | ||
162 | #define CS4231_MISC_INFO 0x0c /* miscellaneaous information */ | ||
163 | #define CS4231_LOOPBACK 0x0d /* loopback control */ | ||
164 | #define CS4231_PLY_UPR_CNT 0x0e /* playback upper base count */ | ||
165 | #define CS4231_PLY_LWR_CNT 0x0f /* playback lower base count */ | ||
166 | #define CS4231_ALT_FEATURE_1 0x10 /* alternate #1 feature enable */ | ||
167 | #define CS4231_ALT_FEATURE_2 0x11 /* alternate #2 feature enable */ | ||
168 | #define CS4231_LEFT_LINE_IN 0x12 /* left line input control */ | ||
169 | #define CS4231_RIGHT_LINE_IN 0x13 /* right line input control */ | ||
170 | #define CS4231_TIMER_LOW 0x14 /* timer low byte */ | ||
171 | #define CS4231_TIMER_HIGH 0x15 /* timer high byte */ | ||
172 | #define CS4231_LEFT_MIC_INPUT 0x16 /* left MIC input control register (InterWave only) */ | ||
173 | #define CS4231_RIGHT_MIC_INPUT 0x17 /* right MIC input control register (InterWave only) */ | ||
174 | #define CS4236_EXT_REG 0x17 /* extended register access */ | ||
175 | #define CS4231_IRQ_STATUS 0x18 /* irq status register */ | ||
176 | #define CS4231_LINE_LEFT_OUTPUT 0x19 /* left line output control register (InterWave only) */ | ||
177 | #define CS4231_VERSION 0x19 /* CS4231(A) - version values */ | ||
178 | #define CS4231_MONO_CTRL 0x1a /* mono input/output control */ | ||
179 | #define CS4231_LINE_RIGHT_OUTPUT 0x1b /* right line output control register (InterWave only) */ | ||
180 | #define CS4235_LEFT_MASTER 0x1b /* left master output control */ | ||
181 | #define CS4231_REC_FORMAT 0x1c /* clock and data format - record - bits 7-0 MCE */ | ||
182 | #define CS4231_PLY_VAR_FREQ 0x1d /* playback variable frequency */ | ||
183 | #define CS4235_RIGHT_MASTER 0x1d /* right master output control */ | ||
184 | #define CS4231_REC_UPR_CNT 0x1e /* record upper count */ | ||
185 | #define CS4231_REC_LWR_CNT 0x1f /* record lower count */ | ||
186 | |||
187 | /* definitions for codec register select port - CODECP( REGSEL ) */ | ||
188 | |||
189 | #define CS4231_INIT 0x80 /* CODEC is initializing */ | ||
190 | #define CS4231_MCE 0x40 /* mode change enable */ | ||
191 | #define CS4231_TRD 0x20 /* transfer request disable */ | ||
192 | |||
193 | /* definitions for codec status register - CODECP( STATUS ) */ | ||
194 | |||
195 | #define CS4231_GLOBALIRQ 0x01 /* IRQ is active */ | ||
196 | |||
197 | /* definitions for codec irq status - CS4231_IRQ_STATUS */ | ||
198 | |||
199 | #define CS4231_PLAYBACK_IRQ 0x10 | ||
200 | #define CS4231_RECORD_IRQ 0x20 | ||
201 | #define CS4231_TIMER_IRQ 0x40 | ||
202 | #define CS4231_ALL_IRQS 0x70 | ||
203 | #define CS4231_REC_UNDERRUN 0x08 | ||
204 | #define CS4231_REC_OVERRUN 0x04 | ||
205 | #define CS4231_PLY_OVERRUN 0x02 | ||
206 | #define CS4231_PLY_UNDERRUN 0x01 | ||
207 | |||
208 | /* definitions for CS4231_LEFT_INPUT and CS4231_RIGHT_INPUT registers */ | ||
209 | |||
210 | #define CS4231_ENABLE_MIC_GAIN 0x20 | ||
211 | |||
212 | #define CS4231_MIXS_LINE 0x00 | ||
213 | #define CS4231_MIXS_AUX1 0x40 | ||
214 | #define CS4231_MIXS_MIC 0x80 | ||
215 | #define CS4231_MIXS_ALL 0xc0 | ||
216 | |||
217 | /* definitions for clock and data format register - CS4231_PLAYBK_FORMAT */ | ||
218 | |||
219 | #define CS4231_LINEAR_8 0x00 /* 8-bit unsigned data */ | ||
220 | #define CS4231_ALAW_8 0x60 /* 8-bit A-law companded */ | ||
221 | #define CS4231_ULAW_8 0x20 /* 8-bit U-law companded */ | ||
222 | #define CS4231_LINEAR_16 0x40 /* 16-bit twos complement data - little endian */ | ||
223 | #define CS4231_LINEAR_16_BIG 0xc0 /* 16-bit twos complement data - big endian */ | ||
224 | #define CS4231_ADPCM_16 0xa0 /* 16-bit ADPCM */ | ||
225 | #define CS4231_STEREO 0x10 /* stereo mode */ | ||
226 | /* bits 3-1 define frequency divisor */ | ||
227 | #define CS4231_XTAL1 0x00 /* 24.576 crystal */ | ||
228 | #define CS4231_XTAL2 0x01 /* 16.9344 crystal */ | ||
229 | |||
230 | /* definitions for interface control register - CS4231_IFACE_CTRL */ | ||
231 | |||
232 | #define CS4231_RECORD_PIO 0x80 /* record PIO enable */ | ||
233 | #define CS4231_PLAYBACK_PIO 0x40 /* playback PIO enable */ | ||
234 | #define CS4231_CALIB_MODE 0x18 /* calibration mode bits */ | ||
235 | #define CS4231_AUTOCALIB 0x08 /* auto calibrate */ | ||
236 | #define CS4231_SINGLE_DMA 0x04 /* use single DMA channel */ | ||
237 | #define CS4231_RECORD_ENABLE 0x02 /* record enable */ | ||
238 | #define CS4231_PLAYBACK_ENABLE 0x01 /* playback enable */ | ||
239 | |||
240 | /* definitions for pin control register - CS4231_PIN_CTRL */ | ||
241 | |||
242 | #define CS4231_IRQ_ENABLE 0x02 /* enable IRQ */ | ||
243 | #define CS4231_XCTL1 0x40 /* external control #1 */ | ||
244 | #define CS4231_XCTL0 0x80 /* external control #0 */ | ||
245 | |||
246 | /* definitions for test and init register - CS4231_TEST_INIT */ | ||
247 | |||
248 | #define CS4231_CALIB_IN_PROGRESS 0x20 /* auto calibrate in progress */ | ||
249 | #define CS4231_DMA_REQUEST 0x10 /* DMA request in progress */ | ||
250 | |||
251 | /* definitions for misc control register - CS4231_MISC_INFO */ | ||
252 | |||
253 | #define CS4231_MODE2 0x40 /* MODE 2 */ | ||
254 | #define CS4231_IW_MODE3 0x6c /* MODE 3 - InterWave enhanced mode */ | ||
255 | #define CS4231_4236_MODE3 0xe0 /* MODE 3 - CS4236+ enhanced mode */ | ||
256 | |||
257 | /* definitions for alternate feature 1 register - CS4231_ALT_FEATURE_1 */ | ||
258 | |||
259 | #define CS4231_DACZ 0x01 /* zero DAC when underrun */ | ||
260 | #define CS4231_TIMER_ENABLE 0x40 /* codec timer enable */ | ||
261 | #define CS4231_OLB 0x80 /* output level bit */ | ||
262 | 142 | ||
263 | /* SBUS DMA register defines. */ | 143 | /* SBUS DMA register defines. */ |
264 | 144 | ||
@@ -339,7 +219,7 @@ static unsigned int rates[14] = { | |||
339 | }; | 219 | }; |
340 | 220 | ||
341 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { | 221 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { |
342 | .count = 14, | 222 | .count = ARRAY_SIZE(rates), |
343 | .list = rates, | 223 | .list = rates, |
344 | }; | 224 | }; |
345 | 225 | ||
@@ -389,116 +269,89 @@ static unsigned char snd_cs4231_original_image[32] = | |||
389 | static u8 __cs4231_readb(struct snd_cs4231 *cp, void __iomem *reg_addr) | 269 | static u8 __cs4231_readb(struct snd_cs4231 *cp, void __iomem *reg_addr) |
390 | { | 270 | { |
391 | #ifdef EBUS_SUPPORT | 271 | #ifdef EBUS_SUPPORT |
392 | if (cp->flags & CS4231_FLAG_EBUS) { | 272 | if (cp->flags & CS4231_FLAG_EBUS) |
393 | return readb(reg_addr); | 273 | return readb(reg_addr); |
394 | } else { | 274 | else |
395 | #endif | 275 | #endif |
396 | #ifdef SBUS_SUPPORT | 276 | #ifdef SBUS_SUPPORT |
397 | return sbus_readb(reg_addr); | 277 | return sbus_readb(reg_addr); |
398 | #endif | 278 | #endif |
399 | #ifdef EBUS_SUPPORT | ||
400 | } | ||
401 | #endif | ||
402 | } | 279 | } |
403 | 280 | ||
404 | static void __cs4231_writeb(struct snd_cs4231 *cp, u8 val, void __iomem *reg_addr) | 281 | static void __cs4231_writeb(struct snd_cs4231 *cp, u8 val, |
282 | void __iomem *reg_addr) | ||
405 | { | 283 | { |
406 | #ifdef EBUS_SUPPORT | 284 | #ifdef EBUS_SUPPORT |
407 | if (cp->flags & CS4231_FLAG_EBUS) { | 285 | if (cp->flags & CS4231_FLAG_EBUS) |
408 | return writeb(val, reg_addr); | 286 | return writeb(val, reg_addr); |
409 | } else { | 287 | else |
410 | #endif | 288 | #endif |
411 | #ifdef SBUS_SUPPORT | 289 | #ifdef SBUS_SUPPORT |
412 | return sbus_writeb(val, reg_addr); | 290 | return sbus_writeb(val, reg_addr); |
413 | #endif | 291 | #endif |
414 | #ifdef EBUS_SUPPORT | ||
415 | } | ||
416 | #endif | ||
417 | } | 292 | } |
418 | 293 | ||
419 | /* | 294 | /* |
420 | * Basic I/O functions | 295 | * Basic I/O functions |
421 | */ | 296 | */ |
422 | 297 | ||
423 | static void snd_cs4231_outm(struct snd_cs4231 *chip, unsigned char reg, | 298 | static void snd_cs4231_ready(struct snd_cs4231 *chip) |
424 | unsigned char mask, unsigned char value) | ||
425 | { | 299 | { |
426 | int timeout; | 300 | int timeout; |
427 | unsigned char tmp; | ||
428 | 301 | ||
429 | for (timeout = 250; | 302 | for (timeout = 250; timeout > 0; timeout--) { |
430 | timeout > 0 && (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT); | 303 | int val = __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
431 | timeout--) | 304 | if ((val & CS4231_INIT) == 0) |
432 | udelay(100); | 305 | break; |
433 | #ifdef CONFIG_SND_DEBUG | 306 | udelay(100); |
434 | if (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT) | ||
435 | snd_printdd("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); | ||
436 | #endif | ||
437 | if (chip->calibrate_mute) { | ||
438 | chip->image[reg] &= mask; | ||
439 | chip->image[reg] |= value; | ||
440 | } else { | ||
441 | __cs4231_writeb(chip, chip->mce_bit | reg, CS4231P(chip, REGSEL)); | ||
442 | mb(); | ||
443 | tmp = (chip->image[reg] & mask) | value; | ||
444 | __cs4231_writeb(chip, tmp, CS4231P(chip, REG)); | ||
445 | chip->image[reg] = tmp; | ||
446 | mb(); | ||
447 | } | 307 | } |
448 | } | 308 | } |
449 | 309 | ||
450 | static void snd_cs4231_dout(struct snd_cs4231 *chip, unsigned char reg, unsigned char value) | 310 | static void snd_cs4231_dout(struct snd_cs4231 *chip, unsigned char reg, |
311 | unsigned char value) | ||
451 | { | 312 | { |
452 | int timeout; | 313 | snd_cs4231_ready(chip); |
453 | |||
454 | for (timeout = 250; | ||
455 | timeout > 0 && (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT); | ||
456 | timeout--) | ||
457 | udelay(100); | ||
458 | #ifdef CONFIG_SND_DEBUG | 314 | #ifdef CONFIG_SND_DEBUG |
459 | if (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT) | 315 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
460 | snd_printdd("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); | 316 | snd_printdd("out: auto calibration time out - reg = 0x%x, " |
317 | "value = 0x%x\n", | ||
318 | reg, value); | ||
461 | #endif | 319 | #endif |
462 | __cs4231_writeb(chip, chip->mce_bit | reg, CS4231P(chip, REGSEL)); | 320 | __cs4231_writeb(chip, chip->mce_bit | reg, CS4231U(chip, REGSEL)); |
463 | __cs4231_writeb(chip, value, CS4231P(chip, REG)); | 321 | wmb(); |
322 | __cs4231_writeb(chip, value, CS4231U(chip, REG)); | ||
464 | mb(); | 323 | mb(); |
465 | } | 324 | } |
466 | 325 | ||
467 | static void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char value) | 326 | static inline void snd_cs4231_outm(struct snd_cs4231 *chip, unsigned char reg, |
327 | unsigned char mask, unsigned char value) | ||
468 | { | 328 | { |
469 | int timeout; | 329 | unsigned char tmp = (chip->image[reg] & mask) | value; |
470 | 330 | ||
471 | for (timeout = 250; | 331 | chip->image[reg] = tmp; |
472 | timeout > 0 && (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT); | 332 | if (!chip->calibrate_mute) |
473 | timeout--) | 333 | snd_cs4231_dout(chip, reg, tmp); |
474 | udelay(100); | 334 | } |
475 | #ifdef CONFIG_SND_DEBUG | 335 | |
476 | if (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT) | 336 | static void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, |
477 | snd_printdd("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); | 337 | unsigned char value) |
478 | #endif | 338 | { |
479 | __cs4231_writeb(chip, chip->mce_bit | reg, CS4231P(chip, REGSEL)); | 339 | snd_cs4231_dout(chip, reg, value); |
480 | __cs4231_writeb(chip, value, CS4231P(chip, REG)); | ||
481 | chip->image[reg] = value; | 340 | chip->image[reg] = value; |
482 | mb(); | 341 | mb(); |
483 | } | 342 | } |
484 | 343 | ||
485 | static unsigned char snd_cs4231_in(struct snd_cs4231 *chip, unsigned char reg) | 344 | static unsigned char snd_cs4231_in(struct snd_cs4231 *chip, unsigned char reg) |
486 | { | 345 | { |
487 | int timeout; | 346 | snd_cs4231_ready(chip); |
488 | unsigned char ret; | ||
489 | |||
490 | for (timeout = 250; | ||
491 | timeout > 0 && (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT); | ||
492 | timeout--) | ||
493 | udelay(100); | ||
494 | #ifdef CONFIG_SND_DEBUG | 347 | #ifdef CONFIG_SND_DEBUG |
495 | if (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT) | 348 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
496 | snd_printdd("in: auto calibration time out - reg = 0x%x\n", reg); | 349 | snd_printdd("in: auto calibration time out - reg = 0x%x\n", |
350 | reg); | ||
497 | #endif | 351 | #endif |
498 | __cs4231_writeb(chip, chip->mce_bit | reg, CS4231P(chip, REGSEL)); | 352 | __cs4231_writeb(chip, chip->mce_bit | reg, CS4231U(chip, REGSEL)); |
499 | mb(); | 353 | mb(); |
500 | ret = __cs4231_readb(chip, CS4231P(chip, REG)); | 354 | return __cs4231_readb(chip, CS4231U(chip, REG)); |
501 | return ret; | ||
502 | } | 355 | } |
503 | 356 | ||
504 | /* | 357 | /* |
@@ -509,15 +362,17 @@ static void snd_cs4231_busy_wait(struct snd_cs4231 *chip) | |||
509 | { | 362 | { |
510 | int timeout; | 363 | int timeout; |
511 | 364 | ||
512 | /* huh.. looks like this sequence is proper for CS4231A chip (GUS MAX) */ | 365 | /* looks like this sequence is proper for CS4231A chip (GUS MAX) */ |
513 | for (timeout = 5; timeout > 0; timeout--) | 366 | for (timeout = 5; timeout > 0; timeout--) |
514 | __cs4231_readb(chip, CS4231P(chip, REGSEL)); | 367 | __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
515 | 368 | ||
516 | /* end of cleanup sequence */ | 369 | /* end of cleanup sequence */ |
517 | for (timeout = 500; | 370 | for (timeout = 500; timeout > 0; timeout--) { |
518 | timeout > 0 && (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT); | 371 | int val = __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
519 | timeout--) | 372 | if ((val & CS4231_INIT) == 0) |
520 | udelay(1000); | 373 | break; |
374 | msleep(1); | ||
375 | } | ||
521 | } | 376 | } |
522 | 377 | ||
523 | static void snd_cs4231_mce_up(struct snd_cs4231 *chip) | 378 | static void snd_cs4231_mce_up(struct snd_cs4231 *chip) |
@@ -526,74 +381,81 @@ static void snd_cs4231_mce_up(struct snd_cs4231 *chip) | |||
526 | int timeout; | 381 | int timeout; |
527 | 382 | ||
528 | spin_lock_irqsave(&chip->lock, flags); | 383 | spin_lock_irqsave(&chip->lock, flags); |
529 | for (timeout = 250; timeout > 0 && (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT); timeout--) | 384 | snd_cs4231_ready(chip); |
530 | udelay(100); | ||
531 | #ifdef CONFIG_SND_DEBUG | 385 | #ifdef CONFIG_SND_DEBUG |
532 | if (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT) | 386 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
533 | snd_printdd("mce_up - auto calibration time out (0)\n"); | 387 | snd_printdd("mce_up - auto calibration time out (0)\n"); |
534 | #endif | 388 | #endif |
535 | chip->mce_bit |= CS4231_MCE; | 389 | chip->mce_bit |= CS4231_MCE; |
536 | timeout = __cs4231_readb(chip, CS4231P(chip, REGSEL)); | 390 | timeout = __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
537 | if (timeout == 0x80) | 391 | if (timeout == 0x80) |
538 | snd_printdd("mce_up [%p]: serious init problem - codec still busy\n", chip->port); | 392 | snd_printdd("mce_up [%p]: serious init problem - " |
393 | "codec still busy\n", | ||
394 | chip->port); | ||
539 | if (!(timeout & CS4231_MCE)) | 395 | if (!(timeout & CS4231_MCE)) |
540 | __cs4231_writeb(chip, chip->mce_bit | (timeout & 0x1f), CS4231P(chip, REGSEL)); | 396 | __cs4231_writeb(chip, chip->mce_bit | (timeout & 0x1f), |
397 | CS4231U(chip, REGSEL)); | ||
541 | spin_unlock_irqrestore(&chip->lock, flags); | 398 | spin_unlock_irqrestore(&chip->lock, flags); |
542 | } | 399 | } |
543 | 400 | ||
544 | static void snd_cs4231_mce_down(struct snd_cs4231 *chip) | 401 | static void snd_cs4231_mce_down(struct snd_cs4231 *chip) |
545 | { | 402 | { |
546 | unsigned long flags; | 403 | unsigned long flags; |
404 | unsigned long end_time; | ||
547 | int timeout; | 405 | int timeout; |
548 | 406 | ||
549 | spin_lock_irqsave(&chip->lock, flags); | 407 | spin_lock_irqsave(&chip->lock, flags); |
550 | snd_cs4231_busy_wait(chip); | 408 | snd_cs4231_busy_wait(chip); |
551 | #ifdef CONFIG_SND_DEBUG | 409 | #ifdef CONFIG_SND_DEBUG |
552 | if (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT) | 410 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
553 | snd_printdd("mce_down [%p] - auto calibration time out (0)\n", CS4231P(chip, REGSEL)); | 411 | snd_printdd("mce_down [%p] - auto calibration time out (0)\n", |
412 | CS4231U(chip, REGSEL)); | ||
554 | #endif | 413 | #endif |
555 | chip->mce_bit &= ~CS4231_MCE; | 414 | chip->mce_bit &= ~CS4231_MCE; |
556 | timeout = __cs4231_readb(chip, CS4231P(chip, REGSEL)); | 415 | timeout = __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
557 | __cs4231_writeb(chip, chip->mce_bit | (timeout & 0x1f), CS4231P(chip, REGSEL)); | 416 | __cs4231_writeb(chip, chip->mce_bit | (timeout & 0x1f), |
417 | CS4231U(chip, REGSEL)); | ||
558 | if (timeout == 0x80) | 418 | if (timeout == 0x80) |
559 | snd_printdd("mce_down [%p]: serious init problem - codec still busy\n", chip->port); | 419 | snd_printdd("mce_down [%p]: serious init problem - " |
420 | "codec still busy\n", | ||
421 | chip->port); | ||
560 | if ((timeout & CS4231_MCE) == 0) { | 422 | if ((timeout & CS4231_MCE) == 0) { |
561 | spin_unlock_irqrestore(&chip->lock, flags); | 423 | spin_unlock_irqrestore(&chip->lock, flags); |
562 | return; | 424 | return; |
563 | } | 425 | } |
564 | snd_cs4231_busy_wait(chip); | ||
565 | 426 | ||
566 | /* calibration process */ | 427 | /* |
428 | * Wait for (possible -- during init auto-calibration may not be set) | ||
429 | * calibration process to start. Needs upto 5 sample periods on AD1848 | ||
430 | * which at the slowest possible rate of 5.5125 kHz means 907 us. | ||
431 | */ | ||
432 | msleep(1); | ||
567 | 433 | ||
568 | for (timeout = 500; timeout > 0 && (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) == 0; timeout--) | 434 | /* check condition up to 250ms */ |
569 | udelay(100); | 435 | end_time = jiffies + msecs_to_jiffies(250); |
570 | if ((snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) == 0) { | 436 | while (snd_cs4231_in(chip, CS4231_TEST_INIT) & |
571 | snd_printd("cs4231_mce_down - auto calibration time out (1)\n"); | 437 | CS4231_CALIB_IN_PROGRESS) { |
572 | spin_unlock_irqrestore(&chip->lock, flags); | ||
573 | return; | ||
574 | } | ||
575 | 438 | ||
576 | /* in 10ms increments, check condition, up to 250ms */ | ||
577 | timeout = 25; | ||
578 | while (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) { | ||
579 | spin_unlock_irqrestore(&chip->lock, flags); | 439 | spin_unlock_irqrestore(&chip->lock, flags); |
580 | if (--timeout < 0) { | 440 | if (time_after(jiffies, end_time)) { |
581 | snd_printk("mce_down - auto calibration time out (2)\n"); | 441 | snd_printk("mce_down - " |
442 | "auto calibration time out (2)\n"); | ||
582 | return; | 443 | return; |
583 | } | 444 | } |
584 | msleep(10); | 445 | msleep(1); |
585 | spin_lock_irqsave(&chip->lock, flags); | 446 | spin_lock_irqsave(&chip->lock, flags); |
586 | } | 447 | } |
587 | 448 | ||
588 | /* in 10ms increments, check condition, up to 100ms */ | 449 | /* check condition up to 100ms */ |
589 | timeout = 10; | 450 | end_time = jiffies + msecs_to_jiffies(100); |
590 | while (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT) { | 451 | while (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) { |
591 | spin_unlock_irqrestore(&chip->lock, flags); | 452 | spin_unlock_irqrestore(&chip->lock, flags); |
592 | if (--timeout < 0) { | 453 | if (time_after(jiffies, end_time)) { |
593 | snd_printk("mce_down - auto calibration time out (3)\n"); | 454 | snd_printk("mce_down - " |
455 | "auto calibration time out (3)\n"); | ||
594 | return; | 456 | return; |
595 | } | 457 | } |
596 | msleep(10); | 458 | msleep(1); |
597 | spin_lock_irqsave(&chip->lock, flags); | 459 | spin_lock_irqsave(&chip->lock, flags); |
598 | } | 460 | } |
599 | spin_unlock_irqrestore(&chip->lock, flags); | 461 | spin_unlock_irqrestore(&chip->lock, flags); |
@@ -611,7 +473,8 @@ static void snd_cs4231_advance_dma(struct cs4231_dma_control *dma_cont, | |||
611 | 473 | ||
612 | BUG_ON(period_size >= (1 << 24)); | 474 | BUG_ON(period_size >= (1 << 24)); |
613 | 475 | ||
614 | if (dma_cont->request(dma_cont, runtime->dma_addr + offset, period_size)) | 476 | if (dma_cont->request(dma_cont, |
477 | runtime->dma_addr + offset, period_size)) | ||
615 | return; | 478 | return; |
616 | (*periods_sent) = ((*periods_sent) + 1) % runtime->periods; | 479 | (*periods_sent) = ((*periods_sent) + 1) % runtime->periods; |
617 | } | 480 | } |
@@ -704,21 +567,32 @@ static unsigned char snd_cs4231_get_rate(unsigned int rate) | |||
704 | for (i = 0; i < 14; i++) | 567 | for (i = 0; i < 14; i++) |
705 | if (rate == rates[i]) | 568 | if (rate == rates[i]) |
706 | return freq_bits[i]; | 569 | return freq_bits[i]; |
707 | // snd_BUG(); | 570 | |
708 | return freq_bits[13]; | 571 | return freq_bits[13]; |
709 | } | 572 | } |
710 | 573 | ||
711 | static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip, int format, int channels) | 574 | static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip, int format, |
575 | int channels) | ||
712 | { | 576 | { |
713 | unsigned char rformat; | 577 | unsigned char rformat; |
714 | 578 | ||
715 | rformat = CS4231_LINEAR_8; | 579 | rformat = CS4231_LINEAR_8; |
716 | switch (format) { | 580 | switch (format) { |
717 | case SNDRV_PCM_FORMAT_MU_LAW: rformat = CS4231_ULAW_8; break; | 581 | case SNDRV_PCM_FORMAT_MU_LAW: |
718 | case SNDRV_PCM_FORMAT_A_LAW: rformat = CS4231_ALAW_8; break; | 582 | rformat = CS4231_ULAW_8; |
719 | case SNDRV_PCM_FORMAT_S16_LE: rformat = CS4231_LINEAR_16; break; | 583 | break; |
720 | case SNDRV_PCM_FORMAT_S16_BE: rformat = CS4231_LINEAR_16_BIG; break; | 584 | case SNDRV_PCM_FORMAT_A_LAW: |
721 | case SNDRV_PCM_FORMAT_IMA_ADPCM: rformat = CS4231_ADPCM_16; break; | 585 | rformat = CS4231_ALAW_8; |
586 | break; | ||
587 | case SNDRV_PCM_FORMAT_S16_LE: | ||
588 | rformat = CS4231_LINEAR_16; | ||
589 | break; | ||
590 | case SNDRV_PCM_FORMAT_S16_BE: | ||
591 | rformat = CS4231_LINEAR_16_BIG; | ||
592 | break; | ||
593 | case SNDRV_PCM_FORMAT_IMA_ADPCM: | ||
594 | rformat = CS4231_ADPCM_16; | ||
595 | break; | ||
722 | } | 596 | } |
723 | if (channels > 1) | 597 | if (channels > 1) |
724 | rformat |= CS4231_STEREO; | 598 | rformat |= CS4231_STEREO; |
@@ -765,7 +639,8 @@ static void snd_cs4231_calibrate_mute(struct snd_cs4231 *chip, int mute) | |||
765 | spin_unlock_irqrestore(&chip->lock, flags); | 639 | spin_unlock_irqrestore(&chip->lock, flags); |
766 | } | 640 | } |
767 | 641 | ||
768 | static void snd_cs4231_playback_format(struct snd_cs4231 *chip, struct snd_pcm_hw_params *params, | 642 | static void snd_cs4231_playback_format(struct snd_cs4231 *chip, |
643 | struct snd_pcm_hw_params *params, | ||
769 | unsigned char pdfr) | 644 | unsigned char pdfr) |
770 | { | 645 | { |
771 | unsigned long flags; | 646 | unsigned long flags; |
@@ -788,8 +663,9 @@ static void snd_cs4231_playback_format(struct snd_cs4231 *chip, struct snd_pcm_h | |||
788 | mutex_unlock(&chip->mce_mutex); | 663 | mutex_unlock(&chip->mce_mutex); |
789 | } | 664 | } |
790 | 665 | ||
791 | static void snd_cs4231_capture_format(struct snd_cs4231 *chip, struct snd_pcm_hw_params *params, | 666 | static void snd_cs4231_capture_format(struct snd_cs4231 *chip, |
792 | unsigned char cdfr) | 667 | struct snd_pcm_hw_params *params, |
668 | unsigned char cdfr) | ||
793 | { | 669 | { |
794 | unsigned long flags; | 670 | unsigned long flags; |
795 | 671 | ||
@@ -846,7 +722,8 @@ static int snd_cs4231_timer_start(struct snd_timer *timer) | |||
846 | chip->image[CS4231_TIMER_LOW] = | 722 | chip->image[CS4231_TIMER_LOW] = |
847 | (unsigned char) ticks); | 723 | (unsigned char) ticks); |
848 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, | 724 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, |
849 | chip->image[CS4231_ALT_FEATURE_1] | CS4231_TIMER_ENABLE); | 725 | chip->image[CS4231_ALT_FEATURE_1] | |
726 | CS4231_TIMER_ENABLE); | ||
850 | } | 727 | } |
851 | spin_unlock_irqrestore(&chip->lock, flags); | 728 | spin_unlock_irqrestore(&chip->lock, flags); |
852 | 729 | ||
@@ -859,8 +736,9 @@ static int snd_cs4231_timer_stop(struct snd_timer *timer) | |||
859 | struct snd_cs4231 *chip = snd_timer_chip(timer); | 736 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
860 | 737 | ||
861 | spin_lock_irqsave(&chip->lock, flags); | 738 | spin_lock_irqsave(&chip->lock, flags); |
739 | chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE; | ||
862 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, | 740 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, |
863 | chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE); | 741 | chip->image[CS4231_ALT_FEATURE_1]); |
864 | spin_unlock_irqrestore(&chip->lock, flags); | 742 | spin_unlock_irqrestore(&chip->lock, flags); |
865 | 743 | ||
866 | return 0; | 744 | return 0; |
@@ -877,8 +755,10 @@ static void __init snd_cs4231_init(struct snd_cs4231 *chip) | |||
877 | #endif | 755 | #endif |
878 | snd_cs4231_mce_up(chip); | 756 | snd_cs4231_mce_up(chip); |
879 | spin_lock_irqsave(&chip->lock, flags); | 757 | spin_lock_irqsave(&chip->lock, flags); |
880 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO | | 758 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | |
881 | CS4231_RECORD_ENABLE | CS4231_RECORD_PIO | | 759 | CS4231_PLAYBACK_PIO | |
760 | CS4231_RECORD_ENABLE | | ||
761 | CS4231_RECORD_PIO | | ||
882 | CS4231_CALIB_MODE); | 762 | CS4231_CALIB_MODE); |
883 | chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB; | 763 | chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB; |
884 | snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]); | 764 | snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]); |
@@ -891,21 +771,25 @@ static void __init snd_cs4231_init(struct snd_cs4231 *chip) | |||
891 | 771 | ||
892 | snd_cs4231_mce_up(chip); | 772 | snd_cs4231_mce_up(chip); |
893 | spin_lock_irqsave(&chip->lock, flags); | 773 | spin_lock_irqsave(&chip->lock, flags); |
894 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1]); | 774 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, |
775 | chip->image[CS4231_ALT_FEATURE_1]); | ||
895 | spin_unlock_irqrestore(&chip->lock, flags); | 776 | spin_unlock_irqrestore(&chip->lock, flags); |
896 | snd_cs4231_mce_down(chip); | 777 | snd_cs4231_mce_down(chip); |
897 | 778 | ||
898 | #ifdef SNDRV_DEBUG_MCE | 779 | #ifdef SNDRV_DEBUG_MCE |
899 | snd_printdd("init: (3) - afei = 0x%x\n", chip->image[CS4231_ALT_FEATURE_1]); | 780 | snd_printdd("init: (3) - afei = 0x%x\n", |
781 | chip->image[CS4231_ALT_FEATURE_1]); | ||
900 | #endif | 782 | #endif |
901 | 783 | ||
902 | spin_lock_irqsave(&chip->lock, flags); | 784 | spin_lock_irqsave(&chip->lock, flags); |
903 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_2, chip->image[CS4231_ALT_FEATURE_2]); | 785 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_2, |
786 | chip->image[CS4231_ALT_FEATURE_2]); | ||
904 | spin_unlock_irqrestore(&chip->lock, flags); | 787 | spin_unlock_irqrestore(&chip->lock, flags); |
905 | 788 | ||
906 | snd_cs4231_mce_up(chip); | 789 | snd_cs4231_mce_up(chip); |
907 | spin_lock_irqsave(&chip->lock, flags); | 790 | spin_lock_irqsave(&chip->lock, flags); |
908 | snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT]); | 791 | snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, |
792 | chip->image[CS4231_PLAYBK_FORMAT]); | ||
909 | spin_unlock_irqrestore(&chip->lock, flags); | 793 | spin_unlock_irqrestore(&chip->lock, flags); |
910 | snd_cs4231_mce_down(chip); | 794 | snd_cs4231_mce_down(chip); |
911 | 795 | ||
@@ -944,8 +828,8 @@ static int snd_cs4231_open(struct snd_cs4231 *chip, unsigned int mode) | |||
944 | CS4231_RECORD_IRQ | | 828 | CS4231_RECORD_IRQ | |
945 | CS4231_TIMER_IRQ); | 829 | CS4231_TIMER_IRQ); |
946 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); | 830 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
947 | __cs4231_writeb(chip, 0, CS4231P(chip, STATUS)); /* clear IRQ */ | 831 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
948 | __cs4231_writeb(chip, 0, CS4231P(chip, STATUS)); /* clear IRQ */ | 832 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
949 | 833 | ||
950 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ | | 834 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ | |
951 | CS4231_RECORD_IRQ | | 835 | CS4231_RECORD_IRQ | |
@@ -974,8 +858,8 @@ static void snd_cs4231_close(struct snd_cs4231 *chip, unsigned int mode) | |||
974 | /* disable IRQ */ | 858 | /* disable IRQ */ |
975 | spin_lock_irqsave(&chip->lock, flags); | 859 | spin_lock_irqsave(&chip->lock, flags); |
976 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); | 860 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
977 | __cs4231_writeb(chip, 0, CS4231P(chip, STATUS)); /* clear IRQ */ | 861 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
978 | __cs4231_writeb(chip, 0, CS4231P(chip, STATUS)); /* clear IRQ */ | 862 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
979 | 863 | ||
980 | /* now disable record & playback */ | 864 | /* now disable record & playback */ |
981 | 865 | ||
@@ -988,7 +872,8 @@ static void snd_cs4231_close(struct snd_cs4231 *chip, unsigned int mode) | |||
988 | chip->image[CS4231_IFACE_CTRL] &= | 872 | chip->image[CS4231_IFACE_CTRL] &= |
989 | ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO | | 873 | ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO | |
990 | CS4231_RECORD_ENABLE | CS4231_RECORD_PIO); | 874 | CS4231_RECORD_ENABLE | CS4231_RECORD_PIO); |
991 | snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]); | 875 | snd_cs4231_out(chip, CS4231_IFACE_CTRL, |
876 | chip->image[CS4231_IFACE_CTRL]); | ||
992 | spin_unlock_irqrestore(&chip->lock, flags); | 877 | spin_unlock_irqrestore(&chip->lock, flags); |
993 | snd_cs4231_mce_down(chip); | 878 | snd_cs4231_mce_down(chip); |
994 | spin_lock_irqsave(&chip->lock, flags); | 879 | spin_lock_irqsave(&chip->lock, flags); |
@@ -996,8 +881,8 @@ static void snd_cs4231_close(struct snd_cs4231 *chip, unsigned int mode) | |||
996 | 881 | ||
997 | /* clear IRQ again */ | 882 | /* clear IRQ again */ |
998 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); | 883 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
999 | __cs4231_writeb(chip, 0, CS4231P(chip, STATUS)); /* clear IRQ */ | 884 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
1000 | __cs4231_writeb(chip, 0, CS4231P(chip, STATUS)); /* clear IRQ */ | 885 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
1001 | spin_unlock_irqrestore(&chip->lock, flags); | 886 | spin_unlock_irqrestore(&chip->lock, flags); |
1002 | 887 | ||
1003 | snd_cs4231_calibrate_mute(chip, 0); | 888 | snd_cs4231_calibrate_mute(chip, 0); |
@@ -1017,15 +902,14 @@ static int snd_cs4231_timer_open(struct snd_timer *timer) | |||
1017 | return 0; | 902 | return 0; |
1018 | } | 903 | } |
1019 | 904 | ||
1020 | static int snd_cs4231_timer_close(struct snd_timer * timer) | 905 | static int snd_cs4231_timer_close(struct snd_timer *timer) |
1021 | { | 906 | { |
1022 | struct snd_cs4231 *chip = snd_timer_chip(timer); | 907 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
1023 | snd_cs4231_close(chip, CS4231_MODE_TIMER); | 908 | snd_cs4231_close(chip, CS4231_MODE_TIMER); |
1024 | return 0; | 909 | return 0; |
1025 | } | 910 | } |
1026 | 911 | ||
1027 | static struct snd_timer_hardware snd_cs4231_timer_table = | 912 | static struct snd_timer_hardware snd_cs4231_timer_table = { |
1028 | { | ||
1029 | .flags = SNDRV_TIMER_HW_AUTO, | 913 | .flags = SNDRV_TIMER_HW_AUTO, |
1030 | .resolution = 9945, | 914 | .resolution = 9945, |
1031 | .ticks = 65535, | 915 | .ticks = 65535, |
@@ -1047,8 +931,9 @@ static int snd_cs4231_playback_hw_params(struct snd_pcm_substream *substream, | |||
1047 | unsigned char new_pdfr; | 931 | unsigned char new_pdfr; |
1048 | int err; | 932 | int err; |
1049 | 933 | ||
1050 | if ((err = snd_pcm_lib_malloc_pages(substream, | 934 | err = snd_pcm_lib_malloc_pages(substream, |
1051 | params_buffer_bytes(hw_params))) < 0) | 935 | params_buffer_bytes(hw_params)); |
936 | if (err < 0) | ||
1052 | return err; | 937 | return err; |
1053 | new_pdfr = snd_cs4231_get_format(chip, params_format(hw_params), | 938 | new_pdfr = snd_cs4231_get_format(chip, params_format(hw_params), |
1054 | params_channels(hw_params)) | | 939 | params_channels(hw_params)) | |
@@ -1058,11 +943,6 @@ static int snd_cs4231_playback_hw_params(struct snd_pcm_substream *substream, | |||
1058 | return 0; | 943 | return 0; |
1059 | } | 944 | } |
1060 | 945 | ||
1061 | static int snd_cs4231_playback_hw_free(struct snd_pcm_substream *substream) | ||
1062 | { | ||
1063 | return snd_pcm_lib_free_pages(substream); | ||
1064 | } | ||
1065 | |||
1066 | static int snd_cs4231_playback_prepare(struct snd_pcm_substream *substream) | 946 | static int snd_cs4231_playback_prepare(struct snd_pcm_substream *substream) |
1067 | { | 947 | { |
1068 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); | 948 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
@@ -1089,8 +969,9 @@ static int snd_cs4231_capture_hw_params(struct snd_pcm_substream *substream, | |||
1089 | unsigned char new_cdfr; | 969 | unsigned char new_cdfr; |
1090 | int err; | 970 | int err; |
1091 | 971 | ||
1092 | if ((err = snd_pcm_lib_malloc_pages(substream, | 972 | err = snd_pcm_lib_malloc_pages(substream, |
1093 | params_buffer_bytes(hw_params))) < 0) | 973 | params_buffer_bytes(hw_params)); |
974 | if (err < 0) | ||
1094 | return err; | 975 | return err; |
1095 | new_cdfr = snd_cs4231_get_format(chip, params_format(hw_params), | 976 | new_cdfr = snd_cs4231_get_format(chip, params_format(hw_params), |
1096 | params_channels(hw_params)) | | 977 | params_channels(hw_params)) | |
@@ -1100,11 +981,6 @@ static int snd_cs4231_capture_hw_params(struct snd_pcm_substream *substream, | |||
1100 | return 0; | 981 | return 0; |
1101 | } | 982 | } |
1102 | 983 | ||
1103 | static int snd_cs4231_capture_hw_free(struct snd_pcm_substream *substream) | ||
1104 | { | ||
1105 | return snd_pcm_lib_free_pages(substream); | ||
1106 | } | ||
1107 | |||
1108 | static int snd_cs4231_capture_prepare(struct snd_pcm_substream *substream) | 984 | static int snd_cs4231_capture_prepare(struct snd_pcm_substream *substream) |
1109 | { | 985 | { |
1110 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); | 986 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
@@ -1130,7 +1006,8 @@ static void snd_cs4231_overrange(struct snd_cs4231 *chip) | |||
1130 | res = snd_cs4231_in(chip, CS4231_TEST_INIT); | 1006 | res = snd_cs4231_in(chip, CS4231_TEST_INIT); |
1131 | spin_unlock_irqrestore(&chip->lock, flags); | 1007 | spin_unlock_irqrestore(&chip->lock, flags); |
1132 | 1008 | ||
1133 | if (res & (0x08 | 0x02)) /* detect overrange only above 0dB; may be user selectable? */ | 1009 | /* detect overrange only above 0dB; may be user selectable? */ |
1010 | if (res & (0x08 | 0x02)) | ||
1134 | chip->capture_substream->runtime->overrange++; | 1011 | chip->capture_substream->runtime->overrange++; |
1135 | } | 1012 | } |
1136 | 1013 | ||
@@ -1152,51 +1029,50 @@ static void snd_cs4231_capture_callback(struct snd_cs4231 *chip) | |||
1152 | } | 1029 | } |
1153 | } | 1030 | } |
1154 | 1031 | ||
1155 | static snd_pcm_uframes_t snd_cs4231_playback_pointer(struct snd_pcm_substream *substream) | 1032 | static snd_pcm_uframes_t snd_cs4231_playback_pointer( |
1033 | struct snd_pcm_substream *substream) | ||
1156 | { | 1034 | { |
1157 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); | 1035 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
1158 | struct cs4231_dma_control *dma_cont = &chip->p_dma; | 1036 | struct cs4231_dma_control *dma_cont = &chip->p_dma; |
1159 | size_t ptr; | 1037 | size_t ptr; |
1160 | 1038 | ||
1161 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) | 1039 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) |
1162 | return 0; | 1040 | return 0; |
1163 | ptr = dma_cont->address(dma_cont); | 1041 | ptr = dma_cont->address(dma_cont); |
1164 | if (ptr != 0) | 1042 | if (ptr != 0) |
1165 | ptr -= substream->runtime->dma_addr; | 1043 | ptr -= substream->runtime->dma_addr; |
1166 | 1044 | ||
1167 | return bytes_to_frames(substream->runtime, ptr); | 1045 | return bytes_to_frames(substream->runtime, ptr); |
1168 | } | 1046 | } |
1169 | 1047 | ||
1170 | static snd_pcm_uframes_t snd_cs4231_capture_pointer(struct snd_pcm_substream *substream) | 1048 | static snd_pcm_uframes_t snd_cs4231_capture_pointer( |
1049 | struct snd_pcm_substream *substream) | ||
1171 | { | 1050 | { |
1172 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); | 1051 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
1173 | struct cs4231_dma_control *dma_cont = &chip->c_dma; | 1052 | struct cs4231_dma_control *dma_cont = &chip->c_dma; |
1174 | size_t ptr; | 1053 | size_t ptr; |
1175 | 1054 | ||
1176 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE)) | 1055 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE)) |
1177 | return 0; | 1056 | return 0; |
1178 | ptr = dma_cont->address(dma_cont); | 1057 | ptr = dma_cont->address(dma_cont); |
1179 | if (ptr != 0) | 1058 | if (ptr != 0) |
1180 | ptr -= substream->runtime->dma_addr; | 1059 | ptr -= substream->runtime->dma_addr; |
1181 | 1060 | ||
1182 | return bytes_to_frames(substream->runtime, ptr); | 1061 | return bytes_to_frames(substream->runtime, ptr); |
1183 | } | 1062 | } |
1184 | 1063 | ||
1185 | /* | ||
1186 | |||
1187 | */ | ||
1188 | |||
1189 | static int __init snd_cs4231_probe(struct snd_cs4231 *chip) | 1064 | static int __init snd_cs4231_probe(struct snd_cs4231 *chip) |
1190 | { | 1065 | { |
1191 | unsigned long flags; | 1066 | unsigned long flags; |
1192 | int i, id, vers; | 1067 | int i; |
1068 | int id = 0; | ||
1069 | int vers = 0; | ||
1193 | unsigned char *ptr; | 1070 | unsigned char *ptr; |
1194 | 1071 | ||
1195 | id = vers = 0; | ||
1196 | for (i = 0; i < 50; i++) { | 1072 | for (i = 0; i < 50; i++) { |
1197 | mb(); | 1073 | mb(); |
1198 | if (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT) | 1074 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
1199 | udelay(2000); | 1075 | msleep(2); |
1200 | else { | 1076 | else { |
1201 | spin_lock_irqsave(&chip->lock, flags); | 1077 | spin_lock_irqsave(&chip->lock, flags); |
1202 | snd_cs4231_out(chip, CS4231_MISC_INFO, CS4231_MODE2); | 1078 | snd_cs4231_out(chip, CS4231_MISC_INFO, CS4231_MODE2); |
@@ -1213,8 +1089,9 @@ static int __init snd_cs4231_probe(struct snd_cs4231 *chip) | |||
1213 | 1089 | ||
1214 | spin_lock_irqsave(&chip->lock, flags); | 1090 | spin_lock_irqsave(&chip->lock, flags); |
1215 | 1091 | ||
1216 | __cs4231_readb(chip, CS4231P(chip, STATUS)); /* clear any pendings IRQ */ | 1092 | /* clear any pendings IRQ */ |
1217 | __cs4231_writeb(chip, 0, CS4231P(chip, STATUS)); | 1093 | __cs4231_readb(chip, CS4231U(chip, STATUS)); |
1094 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); | ||
1218 | mb(); | 1095 | mb(); |
1219 | 1096 | ||
1220 | spin_unlock_irqrestore(&chip->lock, flags); | 1097 | spin_unlock_irqrestore(&chip->lock, flags); |
@@ -1247,42 +1124,50 @@ static int __init snd_cs4231_probe(struct snd_cs4231 *chip) | |||
1247 | return 0; /* all things are ok.. */ | 1124 | return 0; /* all things are ok.. */ |
1248 | } | 1125 | } |
1249 | 1126 | ||
1250 | static struct snd_pcm_hardware snd_cs4231_playback = | 1127 | static struct snd_pcm_hardware snd_cs4231_playback = { |
1251 | { | 1128 | .info = SNDRV_PCM_INFO_MMAP | |
1252 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | | 1129 | SNDRV_PCM_INFO_INTERLEAVED | |
1253 | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START), | 1130 | SNDRV_PCM_INFO_MMAP_VALID | |
1254 | .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | | 1131 | SNDRV_PCM_INFO_SYNC_START, |
1255 | SNDRV_PCM_FMTBIT_IMA_ADPCM | | 1132 | .formats = SNDRV_PCM_FMTBIT_MU_LAW | |
1256 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | | 1133 | SNDRV_PCM_FMTBIT_A_LAW | |
1257 | SNDRV_PCM_FMTBIT_S16_BE), | 1134 | SNDRV_PCM_FMTBIT_IMA_ADPCM | |
1258 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, | 1135 | SNDRV_PCM_FMTBIT_U8 | |
1136 | SNDRV_PCM_FMTBIT_S16_LE | | ||
1137 | SNDRV_PCM_FMTBIT_S16_BE, | ||
1138 | .rates = SNDRV_PCM_RATE_KNOT | | ||
1139 | SNDRV_PCM_RATE_8000_48000, | ||
1259 | .rate_min = 5510, | 1140 | .rate_min = 5510, |
1260 | .rate_max = 48000, | 1141 | .rate_max = 48000, |
1261 | .channels_min = 1, | 1142 | .channels_min = 1, |
1262 | .channels_max = 2, | 1143 | .channels_max = 2, |
1263 | .buffer_bytes_max = (32*1024), | 1144 | .buffer_bytes_max = 32 * 1024, |
1264 | .period_bytes_min = 64, | 1145 | .period_bytes_min = 64, |
1265 | .period_bytes_max = (32*1024), | 1146 | .period_bytes_max = 32 * 1024, |
1266 | .periods_min = 1, | 1147 | .periods_min = 1, |
1267 | .periods_max = 1024, | 1148 | .periods_max = 1024, |
1268 | }; | 1149 | }; |
1269 | 1150 | ||
1270 | static struct snd_pcm_hardware snd_cs4231_capture = | 1151 | static struct snd_pcm_hardware snd_cs4231_capture = { |
1271 | { | 1152 | .info = SNDRV_PCM_INFO_MMAP | |
1272 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | | 1153 | SNDRV_PCM_INFO_INTERLEAVED | |
1273 | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START), | 1154 | SNDRV_PCM_INFO_MMAP_VALID | |
1274 | .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | | 1155 | SNDRV_PCM_INFO_SYNC_START, |
1275 | SNDRV_PCM_FMTBIT_IMA_ADPCM | | 1156 | .formats = SNDRV_PCM_FMTBIT_MU_LAW | |
1276 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | | 1157 | SNDRV_PCM_FMTBIT_A_LAW | |
1277 | SNDRV_PCM_FMTBIT_S16_BE), | 1158 | SNDRV_PCM_FMTBIT_IMA_ADPCM | |
1278 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, | 1159 | SNDRV_PCM_FMTBIT_U8 | |
1160 | SNDRV_PCM_FMTBIT_S16_LE | | ||
1161 | SNDRV_PCM_FMTBIT_S16_BE, | ||
1162 | .rates = SNDRV_PCM_RATE_KNOT | | ||
1163 | SNDRV_PCM_RATE_8000_48000, | ||
1279 | .rate_min = 5510, | 1164 | .rate_min = 5510, |
1280 | .rate_max = 48000, | 1165 | .rate_max = 48000, |
1281 | .channels_min = 1, | 1166 | .channels_min = 1, |
1282 | .channels_max = 2, | 1167 | .channels_max = 2, |
1283 | .buffer_bytes_max = (32*1024), | 1168 | .buffer_bytes_max = 32 * 1024, |
1284 | .period_bytes_min = 64, | 1169 | .period_bytes_min = 64, |
1285 | .period_bytes_max = (32*1024), | 1170 | .period_bytes_max = 32 * 1024, |
1286 | .periods_min = 1, | 1171 | .periods_min = 1, |
1287 | .periods_max = 1024, | 1172 | .periods_max = 1024, |
1288 | }; | 1173 | }; |
@@ -1295,7 +1180,8 @@ static int snd_cs4231_playback_open(struct snd_pcm_substream *substream) | |||
1295 | 1180 | ||
1296 | runtime->hw = snd_cs4231_playback; | 1181 | runtime->hw = snd_cs4231_playback; |
1297 | 1182 | ||
1298 | if ((err = snd_cs4231_open(chip, CS4231_MODE_PLAY)) < 0) { | 1183 | err = snd_cs4231_open(chip, CS4231_MODE_PLAY); |
1184 | if (err < 0) { | ||
1299 | snd_free_pages(runtime->dma_area, runtime->dma_bytes); | 1185 | snd_free_pages(runtime->dma_area, runtime->dma_bytes); |
1300 | return err; | 1186 | return err; |
1301 | } | 1187 | } |
@@ -1315,7 +1201,8 @@ static int snd_cs4231_capture_open(struct snd_pcm_substream *substream) | |||
1315 | 1201 | ||
1316 | runtime->hw = snd_cs4231_capture; | 1202 | runtime->hw = snd_cs4231_capture; |
1317 | 1203 | ||
1318 | if ((err = snd_cs4231_open(chip, CS4231_MODE_RECORD)) < 0) { | 1204 | err = snd_cs4231_open(chip, CS4231_MODE_RECORD); |
1205 | if (err < 0) { | ||
1319 | snd_free_pages(runtime->dma_area, runtime->dma_bytes); | 1206 | snd_free_pages(runtime->dma_area, runtime->dma_bytes); |
1320 | return err; | 1207 | return err; |
1321 | } | 1208 | } |
@@ -1356,7 +1243,7 @@ static struct snd_pcm_ops snd_cs4231_playback_ops = { | |||
1356 | .close = snd_cs4231_playback_close, | 1243 | .close = snd_cs4231_playback_close, |
1357 | .ioctl = snd_pcm_lib_ioctl, | 1244 | .ioctl = snd_pcm_lib_ioctl, |
1358 | .hw_params = snd_cs4231_playback_hw_params, | 1245 | .hw_params = snd_cs4231_playback_hw_params, |
1359 | .hw_free = snd_cs4231_playback_hw_free, | 1246 | .hw_free = snd_pcm_lib_free_pages, |
1360 | .prepare = snd_cs4231_playback_prepare, | 1247 | .prepare = snd_cs4231_playback_prepare, |
1361 | .trigger = snd_cs4231_trigger, | 1248 | .trigger = snd_cs4231_trigger, |
1362 | .pointer = snd_cs4231_playback_pointer, | 1249 | .pointer = snd_cs4231_playback_pointer, |
@@ -1367,23 +1254,27 @@ static struct snd_pcm_ops snd_cs4231_capture_ops = { | |||
1367 | .close = snd_cs4231_capture_close, | 1254 | .close = snd_cs4231_capture_close, |
1368 | .ioctl = snd_pcm_lib_ioctl, | 1255 | .ioctl = snd_pcm_lib_ioctl, |
1369 | .hw_params = snd_cs4231_capture_hw_params, | 1256 | .hw_params = snd_cs4231_capture_hw_params, |
1370 | .hw_free = snd_cs4231_capture_hw_free, | 1257 | .hw_free = snd_pcm_lib_free_pages, |
1371 | .prepare = snd_cs4231_capture_prepare, | 1258 | .prepare = snd_cs4231_capture_prepare, |
1372 | .trigger = snd_cs4231_trigger, | 1259 | .trigger = snd_cs4231_trigger, |
1373 | .pointer = snd_cs4231_capture_pointer, | 1260 | .pointer = snd_cs4231_capture_pointer, |
1374 | }; | 1261 | }; |
1375 | 1262 | ||
1376 | static int __init snd_cs4231_pcm(struct snd_cs4231 *chip) | 1263 | static int __init snd_cs4231_pcm(struct snd_card *card) |
1377 | { | 1264 | { |
1265 | struct snd_cs4231 *chip = card->private_data; | ||
1378 | struct snd_pcm *pcm; | 1266 | struct snd_pcm *pcm; |
1379 | int err; | 1267 | int err; |
1380 | 1268 | ||
1381 | if ((err = snd_pcm_new(chip->card, "CS4231", 0, 1, 1, &pcm)) < 0) | 1269 | err = snd_pcm_new(card, "CS4231", 0, 1, 1, &pcm); |
1270 | if (err < 0) | ||
1382 | return err; | 1271 | return err; |
1383 | 1272 | ||
1384 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs4231_playback_ops); | 1273 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
1385 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cs4231_capture_ops); | 1274 | &snd_cs4231_playback_ops); |
1386 | 1275 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, | |
1276 | &snd_cs4231_capture_ops); | ||
1277 | |||
1387 | /* global setup */ | 1278 | /* global setup */ |
1388 | pcm->private_data = chip; | 1279 | pcm->private_data = chip; |
1389 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; | 1280 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
@@ -1396,8 +1287,9 @@ static int __init snd_cs4231_pcm(struct snd_cs4231 *chip) | |||
1396 | return 0; | 1287 | return 0; |
1397 | } | 1288 | } |
1398 | 1289 | ||
1399 | static int __init snd_cs4231_timer(struct snd_cs4231 *chip) | 1290 | static int __init snd_cs4231_timer(struct snd_card *card) |
1400 | { | 1291 | { |
1292 | struct snd_cs4231 *chip = card->private_data; | ||
1401 | struct snd_timer *timer; | 1293 | struct snd_timer *timer; |
1402 | struct snd_timer_id tid; | 1294 | struct snd_timer_id tid; |
1403 | int err; | 1295 | int err; |
@@ -1405,10 +1297,11 @@ static int __init snd_cs4231_timer(struct snd_cs4231 *chip) | |||
1405 | /* Timer initialization */ | 1297 | /* Timer initialization */ |
1406 | tid.dev_class = SNDRV_TIMER_CLASS_CARD; | 1298 | tid.dev_class = SNDRV_TIMER_CLASS_CARD; |
1407 | tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; | 1299 | tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; |
1408 | tid.card = chip->card->number; | 1300 | tid.card = card->number; |
1409 | tid.device = 0; | 1301 | tid.device = 0; |
1410 | tid.subdevice = 0; | 1302 | tid.subdevice = 0; |
1411 | if ((err = snd_timer_new(chip->card, "CS4231", &tid, &timer)) < 0) | 1303 | err = snd_timer_new(card, "CS4231", &tid, &timer); |
1304 | if (err < 0) | ||
1412 | return err; | 1305 | return err; |
1413 | strcpy(timer->name, "CS4231"); | 1306 | strcpy(timer->name, "CS4231"); |
1414 | timer->private_data = chip; | 1307 | timer->private_data = chip; |
@@ -1417,7 +1310,7 @@ static int __init snd_cs4231_timer(struct snd_cs4231 *chip) | |||
1417 | 1310 | ||
1418 | return 0; | 1311 | return 0; |
1419 | } | 1312 | } |
1420 | 1313 | ||
1421 | /* | 1314 | /* |
1422 | * MIXER part | 1315 | * MIXER part |
1423 | */ | 1316 | */ |
@@ -1428,15 +1321,14 @@ static int snd_cs4231_info_mux(struct snd_kcontrol *kcontrol, | |||
1428 | static char *texts[4] = { | 1321 | static char *texts[4] = { |
1429 | "Line", "CD", "Mic", "Mix" | 1322 | "Line", "CD", "Mic", "Mix" |
1430 | }; | 1323 | }; |
1431 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); | ||
1432 | 1324 | ||
1433 | snd_assert(chip->card != NULL, return -EINVAL); | ||
1434 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | 1325 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
1435 | uinfo->count = 2; | 1326 | uinfo->count = 2; |
1436 | uinfo->value.enumerated.items = 4; | 1327 | uinfo->value.enumerated.items = 4; |
1437 | if (uinfo->value.enumerated.item > 3) | 1328 | if (uinfo->value.enumerated.item > 3) |
1438 | uinfo->value.enumerated.item = 3; | 1329 | uinfo->value.enumerated.item = 3; |
1439 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); | 1330 | strcpy(uinfo->value.enumerated.name, |
1331 | texts[uinfo->value.enumerated.item]); | ||
1440 | 1332 | ||
1441 | return 0; | 1333 | return 0; |
1442 | } | 1334 | } |
@@ -1446,7 +1338,7 @@ static int snd_cs4231_get_mux(struct snd_kcontrol *kcontrol, | |||
1446 | { | 1338 | { |
1447 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); | 1339 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
1448 | unsigned long flags; | 1340 | unsigned long flags; |
1449 | 1341 | ||
1450 | spin_lock_irqsave(&chip->lock, flags); | 1342 | spin_lock_irqsave(&chip->lock, flags); |
1451 | ucontrol->value.enumerated.item[0] = | 1343 | ucontrol->value.enumerated.item[0] = |
1452 | (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6; | 1344 | (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6; |
@@ -1464,7 +1356,7 @@ static int snd_cs4231_put_mux(struct snd_kcontrol *kcontrol, | |||
1464 | unsigned long flags; | 1356 | unsigned long flags; |
1465 | unsigned short left, right; | 1357 | unsigned short left, right; |
1466 | int change; | 1358 | int change; |
1467 | 1359 | ||
1468 | if (ucontrol->value.enumerated.item[0] > 3 || | 1360 | if (ucontrol->value.enumerated.item[0] > 3 || |
1469 | ucontrol->value.enumerated.item[1] > 3) | 1361 | ucontrol->value.enumerated.item[1] > 3) |
1470 | return -EINVAL; | 1362 | return -EINVAL; |
@@ -1476,7 +1368,7 @@ static int snd_cs4231_put_mux(struct snd_kcontrol *kcontrol, | |||
1476 | left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left; | 1368 | left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left; |
1477 | right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right; | 1369 | right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right; |
1478 | change = left != chip->image[CS4231_LEFT_INPUT] || | 1370 | change = left != chip->image[CS4231_LEFT_INPUT] || |
1479 | right != chip->image[CS4231_RIGHT_INPUT]; | 1371 | right != chip->image[CS4231_RIGHT_INPUT]; |
1480 | snd_cs4231_out(chip, CS4231_LEFT_INPUT, left); | 1372 | snd_cs4231_out(chip, CS4231_LEFT_INPUT, left); |
1481 | snd_cs4231_out(chip, CS4231_RIGHT_INPUT, right); | 1373 | snd_cs4231_out(chip, CS4231_RIGHT_INPUT, right); |
1482 | 1374 | ||
@@ -1508,7 +1400,7 @@ static int snd_cs4231_get_single(struct snd_kcontrol *kcontrol, | |||
1508 | int shift = (kcontrol->private_value >> 8) & 0xff; | 1400 | int shift = (kcontrol->private_value >> 8) & 0xff; |
1509 | int mask = (kcontrol->private_value >> 16) & 0xff; | 1401 | int mask = (kcontrol->private_value >> 16) & 0xff; |
1510 | int invert = (kcontrol->private_value >> 24) & 0xff; | 1402 | int invert = (kcontrol->private_value >> 24) & 0xff; |
1511 | 1403 | ||
1512 | spin_lock_irqsave(&chip->lock, flags); | 1404 | spin_lock_irqsave(&chip->lock, flags); |
1513 | 1405 | ||
1514 | ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask; | 1406 | ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask; |
@@ -1533,7 +1425,7 @@ static int snd_cs4231_put_single(struct snd_kcontrol *kcontrol, | |||
1533 | int invert = (kcontrol->private_value >> 24) & 0xff; | 1425 | int invert = (kcontrol->private_value >> 24) & 0xff; |
1534 | int change; | 1426 | int change; |
1535 | unsigned short val; | 1427 | unsigned short val; |
1536 | 1428 | ||
1537 | val = (ucontrol->value.integer.value[0] & mask); | 1429 | val = (ucontrol->value.integer.value[0] & mask); |
1538 | if (invert) | 1430 | if (invert) |
1539 | val = mask - val; | 1431 | val = mask - val; |
@@ -1575,11 +1467,13 @@ static int snd_cs4231_get_double(struct snd_kcontrol *kcontrol, | |||
1575 | int shift_right = (kcontrol->private_value >> 19) & 0x07; | 1467 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
1576 | int mask = (kcontrol->private_value >> 24) & 0xff; | 1468 | int mask = (kcontrol->private_value >> 24) & 0xff; |
1577 | int invert = (kcontrol->private_value >> 22) & 1; | 1469 | int invert = (kcontrol->private_value >> 22) & 1; |
1578 | 1470 | ||
1579 | spin_lock_irqsave(&chip->lock, flags); | 1471 | spin_lock_irqsave(&chip->lock, flags); |
1580 | 1472 | ||
1581 | ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask; | 1473 | ucontrol->value.integer.value[0] = |
1582 | ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask; | 1474 | (chip->image[left_reg] >> shift_left) & mask; |
1475 | ucontrol->value.integer.value[1] = | ||
1476 | (chip->image[right_reg] >> shift_right) & mask; | ||
1583 | 1477 | ||
1584 | spin_unlock_irqrestore(&chip->lock, flags); | 1478 | spin_unlock_irqrestore(&chip->lock, flags); |
1585 | 1479 | ||
@@ -1606,7 +1500,7 @@ static int snd_cs4231_put_double(struct snd_kcontrol *kcontrol, | |||
1606 | int invert = (kcontrol->private_value >> 22) & 1; | 1500 | int invert = (kcontrol->private_value >> 22) & 1; |
1607 | int change; | 1501 | int change; |
1608 | unsigned short val1, val2; | 1502 | unsigned short val1, val2; |
1609 | 1503 | ||
1610 | val1 = ucontrol->value.integer.value[0] & mask; | 1504 | val1 = ucontrol->value.integer.value[0] & mask; |
1611 | val2 = ucontrol->value.integer.value[1] & mask; | 1505 | val2 = ucontrol->value.integer.value[1] & mask; |
1612 | if (invert) { | 1506 | if (invert) { |
@@ -1620,7 +1514,8 @@ static int snd_cs4231_put_double(struct snd_kcontrol *kcontrol, | |||
1620 | 1514 | ||
1621 | val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; | 1515 | val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; |
1622 | val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2; | 1516 | val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2; |
1623 | change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg]; | 1517 | change = val1 != chip->image[left_reg]; |
1518 | change |= val2 != chip->image[right_reg]; | ||
1624 | snd_cs4231_out(chip, left_reg, val1); | 1519 | snd_cs4231_out(chip, left_reg, val1); |
1625 | snd_cs4231_out(chip, right_reg, val2); | 1520 | snd_cs4231_out(chip, right_reg, val2); |
1626 | 1521 | ||
@@ -1630,31 +1525,42 @@ static int snd_cs4231_put_double(struct snd_kcontrol *kcontrol, | |||
1630 | } | 1525 | } |
1631 | 1526 | ||
1632 | #define CS4231_SINGLE(xname, xindex, reg, shift, mask, invert) \ | 1527 | #define CS4231_SINGLE(xname, xindex, reg, shift, mask, invert) \ |
1633 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | 1528 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .index = (xindex), \ |
1634 | .info = snd_cs4231_info_single, \ | 1529 | .info = snd_cs4231_info_single, \ |
1635 | .get = snd_cs4231_get_single, .put = snd_cs4231_put_single, \ | 1530 | .get = snd_cs4231_get_single, .put = snd_cs4231_put_single, \ |
1636 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } | 1531 | .private_value = (reg) | ((shift) << 8) | ((mask) << 16) | ((invert) << 24) } |
1637 | 1532 | ||
1638 | #define CS4231_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ | 1533 | #define CS4231_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, \ |
1639 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ | 1534 | shift_right, mask, invert) \ |
1640 | .info = snd_cs4231_info_double, \ | 1535 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .index = (xindex), \ |
1641 | .get = snd_cs4231_get_double, .put = snd_cs4231_put_double, \ | 1536 | .info = snd_cs4231_info_double, \ |
1642 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } | 1537 | .get = snd_cs4231_get_double, .put = snd_cs4231_put_double, \ |
1538 | .private_value = (left_reg) | ((right_reg) << 8) | ((shift_left) << 16) | \ | ||
1539 | ((shift_right) << 19) | ((mask) << 24) | ((invert) << 22) } | ||
1643 | 1540 | ||
1644 | static struct snd_kcontrol_new snd_cs4231_controls[] __initdata = { | 1541 | static struct snd_kcontrol_new snd_cs4231_controls[] __initdata = { |
1645 | CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), | 1542 | CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, |
1646 | CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), | 1543 | CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), |
1647 | CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), | 1544 | CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, |
1648 | CS4231_DOUBLE("Line Playback Volume", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), | 1545 | CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), |
1649 | CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), | 1546 | CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN, |
1650 | CS4231_DOUBLE("Aux Playback Volume", 0, CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), | 1547 | CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), |
1651 | CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), | 1548 | CS4231_DOUBLE("Line Playback Volume", 0, CS4231_LEFT_LINE_IN, |
1652 | CS4231_DOUBLE("Aux Playback Volume", 1, CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), | 1549 | CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), |
1550 | CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, | ||
1551 | CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), | ||
1552 | CS4231_DOUBLE("Aux Playback Volume", 0, CS4231_AUX1_LEFT_INPUT, | ||
1553 | CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), | ||
1554 | CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, | ||
1555 | CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), | ||
1556 | CS4231_DOUBLE("Aux Playback Volume", 1, CS4231_AUX2_LEFT_INPUT, | ||
1557 | CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), | ||
1653 | CS4231_SINGLE("Mono Playback Switch", 0, CS4231_MONO_CTRL, 7, 1, 1), | 1558 | CS4231_SINGLE("Mono Playback Switch", 0, CS4231_MONO_CTRL, 7, 1, 1), |
1654 | CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), | 1559 | CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), |
1655 | CS4231_SINGLE("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, 6, 1, 1), | 1560 | CS4231_SINGLE("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, 6, 1, 1), |
1656 | CS4231_SINGLE("Mono Output Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0), | 1561 | CS4231_SINGLE("Mono Output Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0), |
1657 | CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0), | 1562 | CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, |
1563 | 15, 0), | ||
1658 | { | 1564 | { |
1659 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 1565 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
1660 | .name = "Capture Source", | 1566 | .name = "Capture Source", |
@@ -1662,29 +1568,28 @@ CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, | |||
1662 | .get = snd_cs4231_get_mux, | 1568 | .get = snd_cs4231_get_mux, |
1663 | .put = snd_cs4231_put_mux, | 1569 | .put = snd_cs4231_put_mux, |
1664 | }, | 1570 | }, |
1665 | CS4231_DOUBLE("Mic Boost", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0), | 1571 | CS4231_DOUBLE("Mic Boost", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, |
1572 | 1, 0), | ||
1666 | CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0), | 1573 | CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0), |
1667 | CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1), | 1574 | CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1), |
1668 | /* SPARC specific uses of XCTL{0,1} general purpose outputs. */ | 1575 | /* SPARC specific uses of XCTL{0,1} general purpose outputs. */ |
1669 | CS4231_SINGLE("Line Out Switch", 0, CS4231_PIN_CTRL, 6, 1, 1), | 1576 | CS4231_SINGLE("Line Out Switch", 0, CS4231_PIN_CTRL, 6, 1, 1), |
1670 | CS4231_SINGLE("Headphone Out Switch", 0, CS4231_PIN_CTRL, 7, 1, 1) | 1577 | CS4231_SINGLE("Headphone Out Switch", 0, CS4231_PIN_CTRL, 7, 1, 1) |
1671 | }; | 1578 | }; |
1672 | 1579 | ||
1673 | static int __init snd_cs4231_mixer(struct snd_cs4231 *chip) | 1580 | static int __init snd_cs4231_mixer(struct snd_card *card) |
1674 | { | 1581 | { |
1675 | struct snd_card *card; | 1582 | struct snd_cs4231 *chip = card->private_data; |
1676 | int err, idx; | 1583 | int err, idx; |
1677 | 1584 | ||
1678 | snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL); | 1585 | snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL); |
1679 | 1586 | ||
1680 | card = chip->card; | ||
1681 | |||
1682 | strcpy(card->mixername, chip->pcm->name); | 1587 | strcpy(card->mixername, chip->pcm->name); |
1683 | 1588 | ||
1684 | for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) { | 1589 | for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) { |
1685 | if ((err = snd_ctl_add(card, | 1590 | err = snd_ctl_add(card, |
1686 | snd_ctl_new1(&snd_cs4231_controls[idx], | 1591 | snd_ctl_new1(&snd_cs4231_controls[idx], chip)); |
1687 | chip))) < 0) | 1592 | if (err < 0) |
1688 | return err; | 1593 | return err; |
1689 | } | 1594 | } |
1690 | return 0; | 1595 | return 0; |
@@ -1695,6 +1600,7 @@ static int dev; | |||
1695 | static int __init cs4231_attach_begin(struct snd_card **rcard) | 1600 | static int __init cs4231_attach_begin(struct snd_card **rcard) |
1696 | { | 1601 | { |
1697 | struct snd_card *card; | 1602 | struct snd_card *card; |
1603 | struct snd_cs4231 *chip; | ||
1698 | 1604 | ||
1699 | *rcard = NULL; | 1605 | *rcard = NULL; |
1700 | 1606 | ||
@@ -1706,31 +1612,40 @@ static int __init cs4231_attach_begin(struct snd_card **rcard) | |||
1706 | return -ENOENT; | 1612 | return -ENOENT; |
1707 | } | 1613 | } |
1708 | 1614 | ||
1709 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); | 1615 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
1616 | sizeof(struct snd_cs4231)); | ||
1710 | if (card == NULL) | 1617 | if (card == NULL) |
1711 | return -ENOMEM; | 1618 | return -ENOMEM; |
1712 | 1619 | ||
1713 | strcpy(card->driver, "CS4231"); | 1620 | strcpy(card->driver, "CS4231"); |
1714 | strcpy(card->shortname, "Sun CS4231"); | 1621 | strcpy(card->shortname, "Sun CS4231"); |
1715 | 1622 | ||
1623 | chip = card->private_data; | ||
1624 | chip->card = card; | ||
1625 | |||
1716 | *rcard = card; | 1626 | *rcard = card; |
1717 | return 0; | 1627 | return 0; |
1718 | } | 1628 | } |
1719 | 1629 | ||
1720 | static int __init cs4231_attach_finish(struct snd_card *card, struct snd_cs4231 *chip) | 1630 | static int __init cs4231_attach_finish(struct snd_card *card) |
1721 | { | 1631 | { |
1632 | struct snd_cs4231 *chip = card->private_data; | ||
1722 | int err; | 1633 | int err; |
1723 | 1634 | ||
1724 | if ((err = snd_cs4231_pcm(chip)) < 0) | 1635 | err = snd_cs4231_pcm(card); |
1636 | if (err < 0) | ||
1725 | goto out_err; | 1637 | goto out_err; |
1726 | 1638 | ||
1727 | if ((err = snd_cs4231_mixer(chip)) < 0) | 1639 | err = snd_cs4231_mixer(card); |
1640 | if (err < 0) | ||
1728 | goto out_err; | 1641 | goto out_err; |
1729 | 1642 | ||
1730 | if ((err = snd_cs4231_timer(chip)) < 0) | 1643 | err = snd_cs4231_timer(card); |
1644 | if (err < 0) | ||
1731 | goto out_err; | 1645 | goto out_err; |
1732 | 1646 | ||
1733 | if ((err = snd_card_register(card)) < 0) | 1647 | err = snd_card_register(card); |
1648 | if (err < 0) | ||
1734 | goto out_err; | 1649 | goto out_err; |
1735 | 1650 | ||
1736 | chip->next = cs4231_list; | 1651 | chip->next = cs4231_list; |
@@ -1754,7 +1669,7 @@ static irqreturn_t snd_cs4231_sbus_interrupt(int irq, void *dev_id) | |||
1754 | struct snd_cs4231 *chip = dev_id; | 1669 | struct snd_cs4231 *chip = dev_id; |
1755 | 1670 | ||
1756 | /*This is IRQ is not raised by the cs4231*/ | 1671 | /*This is IRQ is not raised by the cs4231*/ |
1757 | if (!(__cs4231_readb(chip, CS4231P(chip, STATUS)) & CS4231_GLOBALIRQ)) | 1672 | if (!(__cs4231_readb(chip, CS4231U(chip, STATUS)) & CS4231_GLOBALIRQ)) |
1758 | return IRQ_NONE; | 1673 | return IRQ_NONE; |
1759 | 1674 | ||
1760 | /* ACK the APC interrupt. */ | 1675 | /* ACK the APC interrupt. */ |
@@ -1762,24 +1677,24 @@ static irqreturn_t snd_cs4231_sbus_interrupt(int irq, void *dev_id) | |||
1762 | 1677 | ||
1763 | sbus_writel(csr, chip->port + APCCSR); | 1678 | sbus_writel(csr, chip->port + APCCSR); |
1764 | 1679 | ||
1765 | if ((csr & APC_PDMA_READY) && | 1680 | if ((csr & APC_PDMA_READY) && |
1766 | (csr & APC_PLAY_INT) && | 1681 | (csr & APC_PLAY_INT) && |
1767 | (csr & APC_XINT_PNVA) && | 1682 | (csr & APC_XINT_PNVA) && |
1768 | !(csr & APC_XINT_EMPT)) | 1683 | !(csr & APC_XINT_EMPT)) |
1769 | snd_cs4231_play_callback(chip); | 1684 | snd_cs4231_play_callback(chip); |
1770 | 1685 | ||
1771 | if ((csr & APC_CDMA_READY) && | 1686 | if ((csr & APC_CDMA_READY) && |
1772 | (csr & APC_CAPT_INT) && | 1687 | (csr & APC_CAPT_INT) && |
1773 | (csr & APC_XINT_CNVA) && | 1688 | (csr & APC_XINT_CNVA) && |
1774 | !(csr & APC_XINT_EMPT)) | 1689 | !(csr & APC_XINT_EMPT)) |
1775 | snd_cs4231_capture_callback(chip); | 1690 | snd_cs4231_capture_callback(chip); |
1776 | 1691 | ||
1777 | status = snd_cs4231_in(chip, CS4231_IRQ_STATUS); | 1692 | status = snd_cs4231_in(chip, CS4231_IRQ_STATUS); |
1778 | 1693 | ||
1779 | if (status & CS4231_TIMER_IRQ) { | 1694 | if (status & CS4231_TIMER_IRQ) { |
1780 | if (chip->timer) | 1695 | if (chip->timer) |
1781 | snd_timer_interrupt(chip->timer, chip->timer->sticks); | 1696 | snd_timer_interrupt(chip->timer, chip->timer->sticks); |
1782 | } | 1697 | } |
1783 | 1698 | ||
1784 | if ((status & CS4231_RECORD_IRQ) && (csr & APC_CDMA_READY)) | 1699 | if ((status & CS4231_RECORD_IRQ) && (csr & APC_CDMA_READY)) |
1785 | snd_cs4231_overrange(chip); | 1700 | snd_cs4231_overrange(chip); |
@@ -1796,26 +1711,27 @@ static irqreturn_t snd_cs4231_sbus_interrupt(int irq, void *dev_id) | |||
1796 | * SBUS DMA routines | 1711 | * SBUS DMA routines |
1797 | */ | 1712 | */ |
1798 | 1713 | ||
1799 | static int sbus_dma_request(struct cs4231_dma_control *dma_cont, dma_addr_t bus_addr, size_t len) | 1714 | static int sbus_dma_request(struct cs4231_dma_control *dma_cont, |
1715 | dma_addr_t bus_addr, size_t len) | ||
1800 | { | 1716 | { |
1801 | unsigned long flags; | 1717 | unsigned long flags; |
1802 | u32 test, csr; | 1718 | u32 test, csr; |
1803 | int err; | 1719 | int err; |
1804 | struct sbus_dma_info *base = &dma_cont->sbus_info; | 1720 | struct sbus_dma_info *base = &dma_cont->sbus_info; |
1805 | 1721 | ||
1806 | if (len >= (1 << 24)) | 1722 | if (len >= (1 << 24)) |
1807 | return -EINVAL; | 1723 | return -EINVAL; |
1808 | spin_lock_irqsave(&base->lock, flags); | 1724 | spin_lock_irqsave(&base->lock, flags); |
1809 | csr = sbus_readl(base->regs + APCCSR); | 1725 | csr = sbus_readl(base->regs + APCCSR); |
1810 | err = -EINVAL; | 1726 | err = -EINVAL; |
1811 | test = APC_CDMA_READY; | 1727 | test = APC_CDMA_READY; |
1812 | if ( base->dir == APC_PLAY ) | 1728 | if (base->dir == APC_PLAY) |
1813 | test = APC_PDMA_READY; | 1729 | test = APC_PDMA_READY; |
1814 | if (!(csr & test)) | 1730 | if (!(csr & test)) |
1815 | goto out; | 1731 | goto out; |
1816 | err = -EBUSY; | 1732 | err = -EBUSY; |
1817 | test = APC_XINT_CNVA; | 1733 | test = APC_XINT_CNVA; |
1818 | if ( base->dir == APC_PLAY ) | 1734 | if (base->dir == APC_PLAY) |
1819 | test = APC_XINT_PNVA; | 1735 | test = APC_XINT_PNVA; |
1820 | if (!(csr & test)) | 1736 | if (!(csr & test)) |
1821 | goto out; | 1737 | goto out; |
@@ -1838,7 +1754,7 @@ static void sbus_dma_prepare(struct cs4231_dma_control *dma_cont, int d) | |||
1838 | test = APC_GENL_INT | APC_PLAY_INT | APC_XINT_ENA | | 1754 | test = APC_GENL_INT | APC_PLAY_INT | APC_XINT_ENA | |
1839 | APC_XINT_PLAY | APC_XINT_PEMP | APC_XINT_GENL | | 1755 | APC_XINT_PLAY | APC_XINT_PEMP | APC_XINT_GENL | |
1840 | APC_XINT_PENA; | 1756 | APC_XINT_PENA; |
1841 | if ( base->dir == APC_RECORD ) | 1757 | if (base->dir == APC_RECORD) |
1842 | test = APC_GENL_INT | APC_CAPT_INT | APC_XINT_ENA | | 1758 | test = APC_GENL_INT | APC_CAPT_INT | APC_XINT_ENA | |
1843 | APC_XINT_CAPT | APC_XINT_CEMP | APC_XINT_GENL; | 1759 | APC_XINT_CAPT | APC_XINT_CEMP | APC_XINT_GENL; |
1844 | csr |= test; | 1760 | csr |= test; |
@@ -1856,28 +1772,28 @@ static void sbus_dma_enable(struct cs4231_dma_control *dma_cont, int on) | |||
1856 | if (!on) { | 1772 | if (!on) { |
1857 | sbus_writel(0, base->regs + base->dir + APCNC); | 1773 | sbus_writel(0, base->regs + base->dir + APCNC); |
1858 | sbus_writel(0, base->regs + base->dir + APCNVA); | 1774 | sbus_writel(0, base->regs + base->dir + APCNVA); |
1859 | if ( base->dir == APC_PLAY ) { | 1775 | if (base->dir == APC_PLAY) { |
1860 | sbus_writel(0, base->regs + base->dir + APCC); | 1776 | sbus_writel(0, base->regs + base->dir + APCC); |
1861 | sbus_writel(0, base->regs + base->dir + APCVA); | 1777 | sbus_writel(0, base->regs + base->dir + APCVA); |
1862 | } | 1778 | } |
1863 | 1779 | ||
1864 | udelay(1200); | 1780 | udelay(1200); |
1865 | } | 1781 | } |
1866 | csr = sbus_readl(base->regs + APCCSR); | 1782 | csr = sbus_readl(base->regs + APCCSR); |
1867 | shift = 0; | 1783 | shift = 0; |
1868 | if ( base->dir == APC_PLAY ) | 1784 | if (base->dir == APC_PLAY) |
1869 | shift = 1; | 1785 | shift = 1; |
1870 | if (on) | 1786 | if (on) |
1871 | csr &= ~(APC_CPAUSE << shift); | 1787 | csr &= ~(APC_CPAUSE << shift); |
1872 | else | 1788 | else |
1873 | csr |= (APC_CPAUSE << shift); | 1789 | csr |= (APC_CPAUSE << shift); |
1874 | sbus_writel(csr, base->regs + APCCSR); | 1790 | sbus_writel(csr, base->regs + APCCSR); |
1875 | if (on) | 1791 | if (on) |
1876 | csr |= (APC_CDMA_READY << shift); | 1792 | csr |= (APC_CDMA_READY << shift); |
1877 | else | 1793 | else |
1878 | csr &= ~(APC_CDMA_READY << shift); | 1794 | csr &= ~(APC_CDMA_READY << shift); |
1879 | sbus_writel(csr, base->regs + APCCSR); | 1795 | sbus_writel(csr, base->regs + APCCSR); |
1880 | 1796 | ||
1881 | spin_unlock_irqrestore(&base->lock, flags); | 1797 | spin_unlock_irqrestore(&base->lock, flags); |
1882 | } | 1798 | } |
1883 | 1799 | ||
@@ -1885,14 +1801,14 @@ static unsigned int sbus_dma_addr(struct cs4231_dma_control *dma_cont) | |||
1885 | { | 1801 | { |
1886 | struct sbus_dma_info *base = &dma_cont->sbus_info; | 1802 | struct sbus_dma_info *base = &dma_cont->sbus_info; |
1887 | 1803 | ||
1888 | return sbus_readl(base->regs + base->dir + APCVA); | 1804 | return sbus_readl(base->regs + base->dir + APCVA); |
1889 | } | 1805 | } |
1890 | 1806 | ||
1891 | static void sbus_dma_preallocate(struct snd_cs4231 *chip, struct snd_pcm *pcm) | 1807 | static void sbus_dma_preallocate(struct snd_cs4231 *chip, struct snd_pcm *pcm) |
1892 | { | 1808 | { |
1893 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS, | 1809 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS, |
1894 | snd_dma_sbus_data(chip->dev_u.sdev), | 1810 | snd_dma_sbus_data(chip->dev_u.sdev), |
1895 | 64*1024, 128*1024); | 1811 | 64 * 1024, 128 * 1024); |
1896 | } | 1812 | } |
1897 | 1813 | ||
1898 | /* | 1814 | /* |
@@ -1907,8 +1823,6 @@ static int snd_cs4231_sbus_free(struct snd_cs4231 *chip) | |||
1907 | if (chip->port) | 1823 | if (chip->port) |
1908 | sbus_iounmap(chip->port, chip->regs_size); | 1824 | sbus_iounmap(chip->port, chip->regs_size); |
1909 | 1825 | ||
1910 | kfree(chip); | ||
1911 | |||
1912 | return 0; | 1826 | return 0; |
1913 | } | 1827 | } |
1914 | 1828 | ||
@@ -1925,23 +1839,16 @@ static struct snd_device_ops snd_cs4231_sbus_dev_ops = { | |||
1925 | 1839 | ||
1926 | static int __init snd_cs4231_sbus_create(struct snd_card *card, | 1840 | static int __init snd_cs4231_sbus_create(struct snd_card *card, |
1927 | struct sbus_dev *sdev, | 1841 | struct sbus_dev *sdev, |
1928 | int dev, | 1842 | int dev) |
1929 | struct snd_cs4231 **rchip) | ||
1930 | { | 1843 | { |
1931 | struct snd_cs4231 *chip; | 1844 | struct snd_cs4231 *chip = card->private_data; |
1932 | int err; | 1845 | int err; |
1933 | 1846 | ||
1934 | *rchip = NULL; | ||
1935 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | ||
1936 | if (chip == NULL) | ||
1937 | return -ENOMEM; | ||
1938 | |||
1939 | spin_lock_init(&chip->lock); | 1847 | spin_lock_init(&chip->lock); |
1940 | spin_lock_init(&chip->c_dma.sbus_info.lock); | 1848 | spin_lock_init(&chip->c_dma.sbus_info.lock); |
1941 | spin_lock_init(&chip->p_dma.sbus_info.lock); | 1849 | spin_lock_init(&chip->p_dma.sbus_info.lock); |
1942 | mutex_init(&chip->mce_mutex); | 1850 | mutex_init(&chip->mce_mutex); |
1943 | mutex_init(&chip->open_mutex); | 1851 | mutex_init(&chip->open_mutex); |
1944 | chip->card = card; | ||
1945 | chip->dev_u.sdev = sdev; | 1852 | chip->dev_u.sdev = sdev; |
1946 | chip->regs_size = sdev->reg_addrs[0].reg_size; | 1853 | chip->regs_size = sdev->reg_addrs[0].reg_size; |
1947 | memcpy(&chip->image, &snd_cs4231_original_image, | 1854 | memcpy(&chip->image, &snd_cs4231_original_image, |
@@ -1992,14 +1899,12 @@ static int __init snd_cs4231_sbus_create(struct snd_card *card, | |||
1992 | return err; | 1899 | return err; |
1993 | } | 1900 | } |
1994 | 1901 | ||
1995 | *rchip = chip; | ||
1996 | return 0; | 1902 | return 0; |
1997 | } | 1903 | } |
1998 | 1904 | ||
1999 | static int __init cs4231_sbus_attach(struct sbus_dev *sdev) | 1905 | static int __init cs4231_sbus_attach(struct sbus_dev *sdev) |
2000 | { | 1906 | { |
2001 | struct resource *rp = &sdev->resource[0]; | 1907 | struct resource *rp = &sdev->resource[0]; |
2002 | struct snd_cs4231 *cp; | ||
2003 | struct snd_card *card; | 1908 | struct snd_card *card; |
2004 | int err; | 1909 | int err; |
2005 | 1910 | ||
@@ -2013,25 +1918,28 @@ static int __init cs4231_sbus_attach(struct sbus_dev *sdev) | |||
2013 | (unsigned long long)rp->start, | 1918 | (unsigned long long)rp->start, |
2014 | sdev->irqs[0]); | 1919 | sdev->irqs[0]); |
2015 | 1920 | ||
2016 | if ((err = snd_cs4231_sbus_create(card, sdev, dev, &cp)) < 0) { | 1921 | err = snd_cs4231_sbus_create(card, sdev, dev); |
1922 | if (err < 0) { | ||
2017 | snd_card_free(card); | 1923 | snd_card_free(card); |
2018 | return err; | 1924 | return err; |
2019 | } | 1925 | } |
2020 | 1926 | ||
2021 | return cs4231_attach_finish(card, cp); | 1927 | return cs4231_attach_finish(card); |
2022 | } | 1928 | } |
2023 | #endif | 1929 | #endif |
2024 | 1930 | ||
2025 | #ifdef EBUS_SUPPORT | 1931 | #ifdef EBUS_SUPPORT |
2026 | 1932 | ||
2027 | static void snd_cs4231_ebus_play_callback(struct ebus_dma_info *p, int event, void *cookie) | 1933 | static void snd_cs4231_ebus_play_callback(struct ebus_dma_info *p, int event, |
1934 | void *cookie) | ||
2028 | { | 1935 | { |
2029 | struct snd_cs4231 *chip = cookie; | 1936 | struct snd_cs4231 *chip = cookie; |
2030 | 1937 | ||
2031 | snd_cs4231_play_callback(chip); | 1938 | snd_cs4231_play_callback(chip); |
2032 | } | 1939 | } |
2033 | 1940 | ||
2034 | static void snd_cs4231_ebus_capture_callback(struct ebus_dma_info *p, int event, void *cookie) | 1941 | static void snd_cs4231_ebus_capture_callback(struct ebus_dma_info *p, |
1942 | int event, void *cookie) | ||
2035 | { | 1943 | { |
2036 | struct snd_cs4231 *chip = cookie; | 1944 | struct snd_cs4231 *chip = cookie; |
2037 | 1945 | ||
@@ -2042,7 +1950,8 @@ static void snd_cs4231_ebus_capture_callback(struct ebus_dma_info *p, int event, | |||
2042 | * EBUS DMA wrappers | 1950 | * EBUS DMA wrappers |
2043 | */ | 1951 | */ |
2044 | 1952 | ||
2045 | static int _ebus_dma_request(struct cs4231_dma_control *dma_cont, dma_addr_t bus_addr, size_t len) | 1953 | static int _ebus_dma_request(struct cs4231_dma_control *dma_cont, |
1954 | dma_addr_t bus_addr, size_t len) | ||
2046 | { | 1955 | { |
2047 | return ebus_dma_request(&dma_cont->ebus_info, bus_addr, len); | 1956 | return ebus_dma_request(&dma_cont->ebus_info, bus_addr, len); |
2048 | } | 1957 | } |
@@ -2087,8 +1996,6 @@ static int snd_cs4231_ebus_free(struct snd_cs4231 *chip) | |||
2087 | if (chip->port) | 1996 | if (chip->port) |
2088 | iounmap(chip->port); | 1997 | iounmap(chip->port); |
2089 | 1998 | ||
2090 | kfree(chip); | ||
2091 | |||
2092 | return 0; | 1999 | return 0; |
2093 | } | 2000 | } |
2094 | 2001 | ||
@@ -2105,24 +2012,17 @@ static struct snd_device_ops snd_cs4231_ebus_dev_ops = { | |||
2105 | 2012 | ||
2106 | static int __init snd_cs4231_ebus_create(struct snd_card *card, | 2013 | static int __init snd_cs4231_ebus_create(struct snd_card *card, |
2107 | struct linux_ebus_device *edev, | 2014 | struct linux_ebus_device *edev, |
2108 | int dev, | 2015 | int dev) |
2109 | struct snd_cs4231 **rchip) | ||
2110 | { | 2016 | { |
2111 | struct snd_cs4231 *chip; | 2017 | struct snd_cs4231 *chip = card->private_data; |
2112 | int err; | 2018 | int err; |
2113 | 2019 | ||
2114 | *rchip = NULL; | ||
2115 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | ||
2116 | if (chip == NULL) | ||
2117 | return -ENOMEM; | ||
2118 | |||
2119 | spin_lock_init(&chip->lock); | 2020 | spin_lock_init(&chip->lock); |
2120 | spin_lock_init(&chip->c_dma.ebus_info.lock); | 2021 | spin_lock_init(&chip->c_dma.ebus_info.lock); |
2121 | spin_lock_init(&chip->p_dma.ebus_info.lock); | 2022 | spin_lock_init(&chip->p_dma.ebus_info.lock); |
2122 | mutex_init(&chip->mce_mutex); | 2023 | mutex_init(&chip->mce_mutex); |
2123 | mutex_init(&chip->open_mutex); | 2024 | mutex_init(&chip->open_mutex); |
2124 | chip->flags |= CS4231_FLAG_EBUS; | 2025 | chip->flags |= CS4231_FLAG_EBUS; |
2125 | chip->card = card; | ||
2126 | chip->dev_u.pdev = edev->bus->self; | 2026 | chip->dev_u.pdev = edev->bus->self; |
2127 | memcpy(&chip->image, &snd_cs4231_original_image, | 2027 | memcpy(&chip->image, &snd_cs4231_original_image, |
2128 | sizeof(snd_cs4231_original_image)); | 2028 | sizeof(snd_cs4231_original_image)); |
@@ -2152,7 +2052,8 @@ static int __init snd_cs4231_ebus_create(struct snd_card *card, | |||
2152 | chip->port = ioremap(edev->resource[0].start, 0x10); | 2052 | chip->port = ioremap(edev->resource[0].start, 0x10); |
2153 | chip->p_dma.ebus_info.regs = ioremap(edev->resource[1].start, 0x10); | 2053 | chip->p_dma.ebus_info.regs = ioremap(edev->resource[1].start, 0x10); |
2154 | chip->c_dma.ebus_info.regs = ioremap(edev->resource[2].start, 0x10); | 2054 | chip->c_dma.ebus_info.regs = ioremap(edev->resource[2].start, 0x10); |
2155 | if (!chip->port || !chip->p_dma.ebus_info.regs || !chip->c_dma.ebus_info.regs) { | 2055 | if (!chip->port || !chip->p_dma.ebus_info.regs || |
2056 | !chip->c_dma.ebus_info.regs) { | ||
2156 | snd_cs4231_ebus_free(chip); | 2057 | snd_cs4231_ebus_free(chip); |
2157 | snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev); | 2058 | snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev); |
2158 | return -EIO; | 2059 | return -EIO; |
@@ -2160,18 +2061,21 @@ static int __init snd_cs4231_ebus_create(struct snd_card *card, | |||
2160 | 2061 | ||
2161 | if (ebus_dma_register(&chip->c_dma.ebus_info)) { | 2062 | if (ebus_dma_register(&chip->c_dma.ebus_info)) { |
2162 | snd_cs4231_ebus_free(chip); | 2063 | snd_cs4231_ebus_free(chip); |
2163 | snd_printdd("cs4231-%d: Unable to register EBUS capture DMA\n", dev); | 2064 | snd_printdd("cs4231-%d: Unable to register EBUS capture DMA\n", |
2065 | dev); | ||
2164 | return -EBUSY; | 2066 | return -EBUSY; |
2165 | } | 2067 | } |
2166 | if (ebus_dma_irq_enable(&chip->c_dma.ebus_info, 1)) { | 2068 | if (ebus_dma_irq_enable(&chip->c_dma.ebus_info, 1)) { |
2167 | snd_cs4231_ebus_free(chip); | 2069 | snd_cs4231_ebus_free(chip); |
2168 | snd_printdd("cs4231-%d: Unable to enable EBUS capture IRQ\n", dev); | 2070 | snd_printdd("cs4231-%d: Unable to enable EBUS capture IRQ\n", |
2071 | dev); | ||
2169 | return -EBUSY; | 2072 | return -EBUSY; |
2170 | } | 2073 | } |
2171 | 2074 | ||
2172 | if (ebus_dma_register(&chip->p_dma.ebus_info)) { | 2075 | if (ebus_dma_register(&chip->p_dma.ebus_info)) { |
2173 | snd_cs4231_ebus_free(chip); | 2076 | snd_cs4231_ebus_free(chip); |
2174 | snd_printdd("cs4231-%d: Unable to register EBUS play DMA\n", dev); | 2077 | snd_printdd("cs4231-%d: Unable to register EBUS play DMA\n", |
2078 | dev); | ||
2175 | return -EBUSY; | 2079 | return -EBUSY; |
2176 | } | 2080 | } |
2177 | if (ebus_dma_irq_enable(&chip->p_dma.ebus_info, 1)) { | 2081 | if (ebus_dma_irq_enable(&chip->p_dma.ebus_info, 1)) { |
@@ -2192,14 +2096,12 @@ static int __init snd_cs4231_ebus_create(struct snd_card *card, | |||
2192 | return err; | 2096 | return err; |
2193 | } | 2097 | } |
2194 | 2098 | ||
2195 | *rchip = chip; | ||
2196 | return 0; | 2099 | return 0; |
2197 | } | 2100 | } |
2198 | 2101 | ||
2199 | static int __init cs4231_ebus_attach(struct linux_ebus_device *edev) | 2102 | static int __init cs4231_ebus_attach(struct linux_ebus_device *edev) |
2200 | { | 2103 | { |
2201 | struct snd_card *card; | 2104 | struct snd_card *card; |
2202 | struct snd_cs4231 *chip; | ||
2203 | int err; | 2105 | int err; |
2204 | 2106 | ||
2205 | err = cs4231_attach_begin(&card); | 2107 | err = cs4231_attach_begin(&card); |
@@ -2211,12 +2113,13 @@ static int __init cs4231_ebus_attach(struct linux_ebus_device *edev) | |||
2211 | edev->resource[0].start, | 2113 | edev->resource[0].start, |
2212 | edev->irqs[0]); | 2114 | edev->irqs[0]); |
2213 | 2115 | ||
2214 | if ((err = snd_cs4231_ebus_create(card, edev, dev, &chip)) < 0) { | 2116 | err = snd_cs4231_ebus_create(card, edev, dev); |
2117 | if (err < 0) { | ||
2215 | snd_card_free(card); | 2118 | snd_card_free(card); |
2216 | return err; | 2119 | return err; |
2217 | } | 2120 | } |
2218 | 2121 | ||
2219 | return cs4231_attach_finish(card, chip); | 2122 | return cs4231_attach_finish(card); |
2220 | } | 2123 | } |
2221 | #endif | 2124 | #endif |
2222 | 2125 | ||