2 * Driver for CS4231 sound chips found on Sparcs.
3 * Copyright (C) 2002, 2008 David S. Miller <davem@davemloft.net>
5 * Based entirely upon drivers/sbus/audio/cs4231.c which is:
6 * Copyright (C) 1996, 1997, 1998 Derrick J Brashear (shadow@andrew.cmu.edu)
7 * and also sound/isa/cs423x/cs4231_lib.c which is:
8 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/delay.h>
14 #include <linux/init.h>
15 #include <linux/interrupt.h>
16 #include <linux/moduleparam.h>
17 #include <linux/irq.h>
20 #include <linux/of_device.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/info.h>
25 #include <sound/control.h>
26 #include <sound/timer.h>
27 #include <sound/initval.h>
28 #include <sound/pcm_params.h>
34 #if defined(CONFIG_PCI) && defined(CONFIG_SPARC64)
36 #include <linux/pci.h>
37 #include <asm/ebus_dma.h>
40 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
41 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
42 /* Enable this card */
43 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
45 module_param_array(index
, int, NULL
, 0444);
46 MODULE_PARM_DESC(index
, "Index value for Sun CS4231 soundcard.");
47 module_param_array(id
, charp
, NULL
, 0444);
48 MODULE_PARM_DESC(id
, "ID string for Sun CS4231 soundcard.");
49 module_param_array(enable
, bool, NULL
, 0444);
50 MODULE_PARM_DESC(enable
, "Enable Sun CS4231 soundcard.");
51 MODULE_AUTHOR("Jaroslav Kysela, Derrick J. Brashear and David S. Miller");
52 MODULE_DESCRIPTION("Sun CS4231");
53 MODULE_LICENSE("GPL");
54 MODULE_SUPPORTED_DEVICE("{{Sun,CS4231}}");
57 struct sbus_dma_info
{
58 spinlock_t lock
; /* DMA access lock */
65 struct cs4231_dma_control
{
66 void (*prepare
)(struct cs4231_dma_control
*dma_cont
,
68 void (*enable
)(struct cs4231_dma_control
*dma_cont
, int on
);
69 int (*request
)(struct cs4231_dma_control
*dma_cont
,
70 dma_addr_t bus_addr
, size_t len
);
71 unsigned int (*address
)(struct cs4231_dma_control
*dma_cont
);
73 struct ebus_dma_info ebus_info
;
76 struct sbus_dma_info sbus_info
;
81 spinlock_t lock
; /* registers access lock */
84 struct cs4231_dma_control p_dma
;
85 struct cs4231_dma_control c_dma
;
88 #define CS4231_FLAG_EBUS 0x00000001
89 #define CS4231_FLAG_PLAYBACK 0x00000002
90 #define CS4231_FLAG_CAPTURE 0x00000004
92 struct snd_card
*card
;
94 struct snd_pcm_substream
*playback_substream
;
95 unsigned int p_periods_sent
;
96 struct snd_pcm_substream
*capture_substream
;
97 unsigned int c_periods_sent
;
98 struct snd_timer
*timer
;
101 #define CS4231_MODE_NONE 0x0000
102 #define CS4231_MODE_PLAY 0x0001
103 #define CS4231_MODE_RECORD 0x0002
104 #define CS4231_MODE_TIMER 0x0004
105 #define CS4231_MODE_OPEN (CS4231_MODE_PLAY | CS4231_MODE_RECORD | \
108 unsigned char image
[32]; /* registers image */
111 struct mutex mce_mutex
; /* mutex for mce register */
112 struct mutex open_mutex
; /* mutex for ALSA open/close */
114 struct platform_device
*op
;
116 unsigned int regs_size
;
117 struct snd_cs4231
*next
;
120 /* Eventually we can use sound/isa/cs423x/cs4231_lib.c directly, but for
125 #include <sound/cs4231-regs.h>
127 #define CS4231U(chip, x) ((chip)->port + ((c_d_c_CS4231##x) << 2))
129 /* SBUS DMA register defines. */
131 #define APCCSR 0x10UL /* APC DMA CSR */
132 #define APCCVA 0x20UL /* APC Capture DMA Address */
133 #define APCCC 0x24UL /* APC Capture Count */
134 #define APCCNVA 0x28UL /* APC Capture DMA Next Address */
135 #define APCCNC 0x2cUL /* APC Capture Next Count */
136 #define APCPVA 0x30UL /* APC Play DMA Address */
137 #define APCPC 0x34UL /* APC Play Count */
138 #define APCPNVA 0x38UL /* APC Play DMA Next Address */
139 #define APCPNC 0x3cUL /* APC Play Next Count */
141 /* Defines for SBUS DMA-routines */
143 #define APCVA 0x0UL /* APC DMA Address */
144 #define APCC 0x4UL /* APC Count */
145 #define APCNVA 0x8UL /* APC DMA Next Address */
146 #define APCNC 0xcUL /* APC Next Count */
147 #define APC_PLAY 0x30UL /* Play registers start at 0x30 */
148 #define APC_RECORD 0x20UL /* Record registers start at 0x20 */
152 #define APC_INT_PENDING 0x800000 /* Interrupt Pending */
153 #define APC_PLAY_INT 0x400000 /* Playback interrupt */
154 #define APC_CAPT_INT 0x200000 /* Capture interrupt */
155 #define APC_GENL_INT 0x100000 /* General interrupt */
156 #define APC_XINT_ENA 0x80000 /* General ext int. enable */
157 #define APC_XINT_PLAY 0x40000 /* Playback ext intr */
158 #define APC_XINT_CAPT 0x20000 /* Capture ext intr */
159 #define APC_XINT_GENL 0x10000 /* Error ext intr */
160 #define APC_XINT_EMPT 0x8000 /* Pipe empty interrupt (0 write to pva) */
161 #define APC_XINT_PEMP 0x4000 /* Play pipe empty (pva and pnva not set) */
162 #define APC_XINT_PNVA 0x2000 /* Playback NVA dirty */
163 #define APC_XINT_PENA 0x1000 /* play pipe empty Int enable */
164 #define APC_XINT_COVF 0x800 /* Cap data dropped on floor */
165 #define APC_XINT_CNVA 0x400 /* Capture NVA dirty */
166 #define APC_XINT_CEMP 0x200 /* Capture pipe empty (cva and cnva not set) */
167 #define APC_XINT_CENA 0x100 /* Cap. pipe empty int enable */
168 #define APC_PPAUSE 0x80 /* Pause the play DMA */
169 #define APC_CPAUSE 0x40 /* Pause the capture DMA */
170 #define APC_CDC_RESET 0x20 /* CODEC RESET */
171 #define APC_PDMA_READY 0x08 /* Play DMA Go */
172 #define APC_CDMA_READY 0x04 /* Capture DMA Go */
173 #define APC_CHIP_RESET 0x01 /* Reset the chip */
175 /* EBUS DMA register offsets */
177 #define EBDMA_CSR 0x00UL /* Control/Status */
178 #define EBDMA_ADDR 0x04UL /* DMA Address */
179 #define EBDMA_COUNT 0x08UL /* DMA Count */
185 static unsigned char freq_bits
[14] = {
186 /* 5510 */ 0x00 | CS4231_XTAL2
,
187 /* 6620 */ 0x0E | CS4231_XTAL2
,
188 /* 8000 */ 0x00 | CS4231_XTAL1
,
189 /* 9600 */ 0x0E | CS4231_XTAL1
,
190 /* 11025 */ 0x02 | CS4231_XTAL2
,
191 /* 16000 */ 0x02 | CS4231_XTAL1
,
192 /* 18900 */ 0x04 | CS4231_XTAL2
,
193 /* 22050 */ 0x06 | CS4231_XTAL2
,
194 /* 27042 */ 0x04 | CS4231_XTAL1
,
195 /* 32000 */ 0x06 | CS4231_XTAL1
,
196 /* 33075 */ 0x0C | CS4231_XTAL2
,
197 /* 37800 */ 0x08 | CS4231_XTAL2
,
198 /* 44100 */ 0x0A | CS4231_XTAL2
,
199 /* 48000 */ 0x0C | CS4231_XTAL1
202 static unsigned int rates
[14] = {
203 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050,
204 27042, 32000, 33075, 37800, 44100, 48000
207 static struct snd_pcm_hw_constraint_list hw_constraints_rates
= {
208 .count
= ARRAY_SIZE(rates
),
212 static int snd_cs4231_xrate(struct snd_pcm_runtime
*runtime
)
214 return snd_pcm_hw_constraint_list(runtime
, 0,
215 SNDRV_PCM_HW_PARAM_RATE
,
216 &hw_constraints_rates
);
219 static unsigned char snd_cs4231_original_image
[32] =
221 0x00, /* 00/00 - lic */
222 0x00, /* 01/01 - ric */
223 0x9f, /* 02/02 - la1ic */
224 0x9f, /* 03/03 - ra1ic */
225 0x9f, /* 04/04 - la2ic */
226 0x9f, /* 05/05 - ra2ic */
227 0xbf, /* 06/06 - loc */
228 0xbf, /* 07/07 - roc */
229 0x20, /* 08/08 - pdfr */
230 CS4231_AUTOCALIB
, /* 09/09 - ic */
231 0x00, /* 0a/10 - pc */
232 0x00, /* 0b/11 - ti */
233 CS4231_MODE2
, /* 0c/12 - mi */
234 0x00, /* 0d/13 - lbc */
235 0x00, /* 0e/14 - pbru */
236 0x00, /* 0f/15 - pbrl */
237 0x80, /* 10/16 - afei */
238 0x01, /* 11/17 - afeii */
239 0x9f, /* 12/18 - llic */
240 0x9f, /* 13/19 - rlic */
241 0x00, /* 14/20 - tlb */
242 0x00, /* 15/21 - thb */
243 0x00, /* 16/22 - la3mic/reserved */
244 0x00, /* 17/23 - ra3mic/reserved */
245 0x00, /* 18/24 - afs */
246 0x00, /* 19/25 - lamoc/version */
247 0x00, /* 1a/26 - mioc */
248 0x00, /* 1b/27 - ramoc/reserved */
249 0x20, /* 1c/28 - cdfr */
250 0x00, /* 1d/29 - res4 */
251 0x00, /* 1e/30 - cbru */
252 0x00, /* 1f/31 - cbrl */
255 static u8
__cs4231_readb(struct snd_cs4231
*cp
, void __iomem
*reg_addr
)
257 if (cp
->flags
& CS4231_FLAG_EBUS
)
258 return readb(reg_addr
);
260 return sbus_readb(reg_addr
);
263 static void __cs4231_writeb(struct snd_cs4231
*cp
, u8 val
,
264 void __iomem
*reg_addr
)
266 if (cp
->flags
& CS4231_FLAG_EBUS
)
267 return writeb(val
, reg_addr
);
269 return sbus_writeb(val
, reg_addr
);
273 * Basic I/O functions
276 static void snd_cs4231_ready(struct snd_cs4231
*chip
)
280 for (timeout
= 250; timeout
> 0; timeout
--) {
281 int val
= __cs4231_readb(chip
, CS4231U(chip
, REGSEL
));
282 if ((val
& CS4231_INIT
) == 0)
288 static void snd_cs4231_dout(struct snd_cs4231
*chip
, unsigned char reg
,
291 snd_cs4231_ready(chip
);
292 #ifdef CONFIG_SND_DEBUG
293 if (__cs4231_readb(chip
, CS4231U(chip
, REGSEL
)) & CS4231_INIT
)
294 snd_printdd("out: auto calibration time out - reg = 0x%x, "
298 __cs4231_writeb(chip
, chip
->mce_bit
| reg
, CS4231U(chip
, REGSEL
));
300 __cs4231_writeb(chip
, value
, CS4231U(chip
, REG
));
304 static inline void snd_cs4231_outm(struct snd_cs4231
*chip
, unsigned char reg
,
305 unsigned char mask
, unsigned char value
)
307 unsigned char tmp
= (chip
->image
[reg
] & mask
) | value
;
309 chip
->image
[reg
] = tmp
;
310 if (!chip
->calibrate_mute
)
311 snd_cs4231_dout(chip
, reg
, tmp
);
314 static void snd_cs4231_out(struct snd_cs4231
*chip
, unsigned char reg
,
317 snd_cs4231_dout(chip
, reg
, value
);
318 chip
->image
[reg
] = value
;
322 static unsigned char snd_cs4231_in(struct snd_cs4231
*chip
, unsigned char reg
)
324 snd_cs4231_ready(chip
);
325 #ifdef CONFIG_SND_DEBUG
326 if (__cs4231_readb(chip
, CS4231U(chip
, REGSEL
)) & CS4231_INIT
)
327 snd_printdd("in: auto calibration time out - reg = 0x%x\n",
330 __cs4231_writeb(chip
, chip
->mce_bit
| reg
, CS4231U(chip
, REGSEL
));
332 return __cs4231_readb(chip
, CS4231U(chip
, REG
));
336 * CS4231 detection / MCE routines
339 static void snd_cs4231_busy_wait(struct snd_cs4231
*chip
)
343 /* looks like this sequence is proper for CS4231A chip (GUS MAX) */
344 for (timeout
= 5; timeout
> 0; timeout
--)
345 __cs4231_readb(chip
, CS4231U(chip
, REGSEL
));
347 /* end of cleanup sequence */
348 for (timeout
= 500; timeout
> 0; timeout
--) {
349 int val
= __cs4231_readb(chip
, CS4231U(chip
, REGSEL
));
350 if ((val
& CS4231_INIT
) == 0)
356 static void snd_cs4231_mce_up(struct snd_cs4231
*chip
)
361 spin_lock_irqsave(&chip
->lock
, flags
);
362 snd_cs4231_ready(chip
);
363 #ifdef CONFIG_SND_DEBUG
364 if (__cs4231_readb(chip
, CS4231U(chip
, REGSEL
)) & CS4231_INIT
)
365 snd_printdd("mce_up - auto calibration time out (0)\n");
367 chip
->mce_bit
|= CS4231_MCE
;
368 timeout
= __cs4231_readb(chip
, CS4231U(chip
, REGSEL
));
370 snd_printdd("mce_up [%p]: serious init problem - "
371 "codec still busy\n",
373 if (!(timeout
& CS4231_MCE
))
374 __cs4231_writeb(chip
, chip
->mce_bit
| (timeout
& 0x1f),
375 CS4231U(chip
, REGSEL
));
376 spin_unlock_irqrestore(&chip
->lock
, flags
);
379 static void snd_cs4231_mce_down(struct snd_cs4231
*chip
)
381 unsigned long flags
, timeout
;
384 snd_cs4231_busy_wait(chip
);
385 spin_lock_irqsave(&chip
->lock
, flags
);
386 #ifdef CONFIG_SND_DEBUG
387 if (__cs4231_readb(chip
, CS4231U(chip
, REGSEL
)) & CS4231_INIT
)
388 snd_printdd("mce_down [%p] - auto calibration time out (0)\n",
389 CS4231U(chip
, REGSEL
));
391 chip
->mce_bit
&= ~CS4231_MCE
;
392 reg
= __cs4231_readb(chip
, CS4231U(chip
, REGSEL
));
393 __cs4231_writeb(chip
, chip
->mce_bit
| (reg
& 0x1f),
394 CS4231U(chip
, REGSEL
));
396 snd_printdd("mce_down [%p]: serious init problem "
397 "- codec still busy\n", chip
->port
);
398 if ((reg
& CS4231_MCE
) == 0) {
399 spin_unlock_irqrestore(&chip
->lock
, flags
);
404 * Wait for auto-calibration (AC) process to finish, i.e. ACI to go low.
406 timeout
= jiffies
+ msecs_to_jiffies(250);
408 spin_unlock_irqrestore(&chip
->lock
, flags
);
410 spin_lock_irqsave(&chip
->lock
, flags
);
411 reg
= snd_cs4231_in(chip
, CS4231_TEST_INIT
);
412 reg
&= CS4231_CALIB_IN_PROGRESS
;
413 } while (reg
&& time_before(jiffies
, timeout
));
414 spin_unlock_irqrestore(&chip
->lock
, flags
);
418 "mce_down - auto calibration time out (2)\n");
421 static void snd_cs4231_advance_dma(struct cs4231_dma_control
*dma_cont
,
422 struct snd_pcm_substream
*substream
,
423 unsigned int *periods_sent
)
425 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
428 unsigned int period_size
= snd_pcm_lib_period_bytes(substream
);
429 unsigned int offset
= period_size
* (*periods_sent
);
431 BUG_ON(period_size
>= (1 << 24));
433 if (dma_cont
->request(dma_cont
,
434 runtime
->dma_addr
+ offset
, period_size
))
436 (*periods_sent
) = ((*periods_sent
) + 1) % runtime
->periods
;
440 static void cs4231_dma_trigger(struct snd_pcm_substream
*substream
,
441 unsigned int what
, int on
)
443 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
444 struct cs4231_dma_control
*dma_cont
;
446 if (what
& CS4231_PLAYBACK_ENABLE
) {
447 dma_cont
= &chip
->p_dma
;
449 dma_cont
->prepare(dma_cont
, 0);
450 dma_cont
->enable(dma_cont
, 1);
451 snd_cs4231_advance_dma(dma_cont
,
452 chip
->playback_substream
,
453 &chip
->p_periods_sent
);
455 dma_cont
->enable(dma_cont
, 0);
458 if (what
& CS4231_RECORD_ENABLE
) {
459 dma_cont
= &chip
->c_dma
;
461 dma_cont
->prepare(dma_cont
, 1);
462 dma_cont
->enable(dma_cont
, 1);
463 snd_cs4231_advance_dma(dma_cont
,
464 chip
->capture_substream
,
465 &chip
->c_periods_sent
);
467 dma_cont
->enable(dma_cont
, 0);
472 static int snd_cs4231_trigger(struct snd_pcm_substream
*substream
, int cmd
)
474 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
478 case SNDRV_PCM_TRIGGER_START
:
479 case SNDRV_PCM_TRIGGER_STOP
:
481 unsigned int what
= 0;
482 struct snd_pcm_substream
*s
;
485 snd_pcm_group_for_each_entry(s
, substream
) {
486 if (s
== chip
->playback_substream
) {
487 what
|= CS4231_PLAYBACK_ENABLE
;
488 snd_pcm_trigger_done(s
, substream
);
489 } else if (s
== chip
->capture_substream
) {
490 what
|= CS4231_RECORD_ENABLE
;
491 snd_pcm_trigger_done(s
, substream
);
495 spin_lock_irqsave(&chip
->lock
, flags
);
496 if (cmd
== SNDRV_PCM_TRIGGER_START
) {
497 cs4231_dma_trigger(substream
, what
, 1);
498 chip
->image
[CS4231_IFACE_CTRL
] |= what
;
500 cs4231_dma_trigger(substream
, what
, 0);
501 chip
->image
[CS4231_IFACE_CTRL
] &= ~what
;
503 snd_cs4231_out(chip
, CS4231_IFACE_CTRL
,
504 chip
->image
[CS4231_IFACE_CTRL
]);
505 spin_unlock_irqrestore(&chip
->lock
, flags
);
520 static unsigned char snd_cs4231_get_rate(unsigned int rate
)
524 for (i
= 0; i
< 14; i
++)
525 if (rate
== rates
[i
])
528 return freq_bits
[13];
531 static unsigned char snd_cs4231_get_format(struct snd_cs4231
*chip
, int format
,
534 unsigned char rformat
;
536 rformat
= CS4231_LINEAR_8
;
538 case SNDRV_PCM_FORMAT_MU_LAW
:
539 rformat
= CS4231_ULAW_8
;
541 case SNDRV_PCM_FORMAT_A_LAW
:
542 rformat
= CS4231_ALAW_8
;
544 case SNDRV_PCM_FORMAT_S16_LE
:
545 rformat
= CS4231_LINEAR_16
;
547 case SNDRV_PCM_FORMAT_S16_BE
:
548 rformat
= CS4231_LINEAR_16_BIG
;
550 case SNDRV_PCM_FORMAT_IMA_ADPCM
:
551 rformat
= CS4231_ADPCM_16
;
555 rformat
|= CS4231_STEREO
;
559 static void snd_cs4231_calibrate_mute(struct snd_cs4231
*chip
, int mute
)
564 spin_lock_irqsave(&chip
->lock
, flags
);
565 if (chip
->calibrate_mute
== mute
) {
566 spin_unlock_irqrestore(&chip
->lock
, flags
);
570 snd_cs4231_dout(chip
, CS4231_LEFT_INPUT
,
571 chip
->image
[CS4231_LEFT_INPUT
]);
572 snd_cs4231_dout(chip
, CS4231_RIGHT_INPUT
,
573 chip
->image
[CS4231_RIGHT_INPUT
]);
574 snd_cs4231_dout(chip
, CS4231_LOOPBACK
,
575 chip
->image
[CS4231_LOOPBACK
]);
577 snd_cs4231_dout(chip
, CS4231_AUX1_LEFT_INPUT
,
578 mute
? 0x80 : chip
->image
[CS4231_AUX1_LEFT_INPUT
]);
579 snd_cs4231_dout(chip
, CS4231_AUX1_RIGHT_INPUT
,
580 mute
? 0x80 : chip
->image
[CS4231_AUX1_RIGHT_INPUT
]);
581 snd_cs4231_dout(chip
, CS4231_AUX2_LEFT_INPUT
,
582 mute
? 0x80 : chip
->image
[CS4231_AUX2_LEFT_INPUT
]);
583 snd_cs4231_dout(chip
, CS4231_AUX2_RIGHT_INPUT
,
584 mute
? 0x80 : chip
->image
[CS4231_AUX2_RIGHT_INPUT
]);
585 snd_cs4231_dout(chip
, CS4231_LEFT_OUTPUT
,
586 mute
? 0x80 : chip
->image
[CS4231_LEFT_OUTPUT
]);
587 snd_cs4231_dout(chip
, CS4231_RIGHT_OUTPUT
,
588 mute
? 0x80 : chip
->image
[CS4231_RIGHT_OUTPUT
]);
589 snd_cs4231_dout(chip
, CS4231_LEFT_LINE_IN
,
590 mute
? 0x80 : chip
->image
[CS4231_LEFT_LINE_IN
]);
591 snd_cs4231_dout(chip
, CS4231_RIGHT_LINE_IN
,
592 mute
? 0x80 : chip
->image
[CS4231_RIGHT_LINE_IN
]);
593 snd_cs4231_dout(chip
, CS4231_MONO_CTRL
,
594 mute
? 0xc0 : chip
->image
[CS4231_MONO_CTRL
]);
595 chip
->calibrate_mute
= mute
;
596 spin_unlock_irqrestore(&chip
->lock
, flags
);
599 static void snd_cs4231_playback_format(struct snd_cs4231
*chip
,
600 struct snd_pcm_hw_params
*params
,
605 mutex_lock(&chip
->mce_mutex
);
606 snd_cs4231_calibrate_mute(chip
, 1);
608 snd_cs4231_mce_up(chip
);
610 spin_lock_irqsave(&chip
->lock
, flags
);
611 snd_cs4231_out(chip
, CS4231_PLAYBK_FORMAT
,
612 (chip
->image
[CS4231_IFACE_CTRL
] & CS4231_RECORD_ENABLE
) ?
613 (pdfr
& 0xf0) | (chip
->image
[CS4231_REC_FORMAT
] & 0x0f) :
615 spin_unlock_irqrestore(&chip
->lock
, flags
);
617 snd_cs4231_mce_down(chip
);
619 snd_cs4231_calibrate_mute(chip
, 0);
620 mutex_unlock(&chip
->mce_mutex
);
623 static void snd_cs4231_capture_format(struct snd_cs4231
*chip
,
624 struct snd_pcm_hw_params
*params
,
629 mutex_lock(&chip
->mce_mutex
);
630 snd_cs4231_calibrate_mute(chip
, 1);
632 snd_cs4231_mce_up(chip
);
634 spin_lock_irqsave(&chip
->lock
, flags
);
635 if (!(chip
->image
[CS4231_IFACE_CTRL
] & CS4231_PLAYBACK_ENABLE
)) {
636 snd_cs4231_out(chip
, CS4231_PLAYBK_FORMAT
,
637 ((chip
->image
[CS4231_PLAYBK_FORMAT
]) & 0xf0) |
639 spin_unlock_irqrestore(&chip
->lock
, flags
);
640 snd_cs4231_mce_down(chip
);
641 snd_cs4231_mce_up(chip
);
642 spin_lock_irqsave(&chip
->lock
, flags
);
644 snd_cs4231_out(chip
, CS4231_REC_FORMAT
, cdfr
);
645 spin_unlock_irqrestore(&chip
->lock
, flags
);
647 snd_cs4231_mce_down(chip
);
649 snd_cs4231_calibrate_mute(chip
, 0);
650 mutex_unlock(&chip
->mce_mutex
);
657 static unsigned long snd_cs4231_timer_resolution(struct snd_timer
*timer
)
659 struct snd_cs4231
*chip
= snd_timer_chip(timer
);
661 return chip
->image
[CS4231_PLAYBK_FORMAT
] & 1 ? 9969 : 9920;
664 static int snd_cs4231_timer_start(struct snd_timer
*timer
)
668 struct snd_cs4231
*chip
= snd_timer_chip(timer
);
670 spin_lock_irqsave(&chip
->lock
, flags
);
671 ticks
= timer
->sticks
;
672 if ((chip
->image
[CS4231_ALT_FEATURE_1
] & CS4231_TIMER_ENABLE
) == 0 ||
673 (unsigned char)(ticks
>> 8) != chip
->image
[CS4231_TIMER_HIGH
] ||
674 (unsigned char)ticks
!= chip
->image
[CS4231_TIMER_LOW
]) {
675 snd_cs4231_out(chip
, CS4231_TIMER_HIGH
,
676 chip
->image
[CS4231_TIMER_HIGH
] =
677 (unsigned char) (ticks
>> 8));
678 snd_cs4231_out(chip
, CS4231_TIMER_LOW
,
679 chip
->image
[CS4231_TIMER_LOW
] =
680 (unsigned char) ticks
);
681 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_1
,
682 chip
->image
[CS4231_ALT_FEATURE_1
] |
683 CS4231_TIMER_ENABLE
);
685 spin_unlock_irqrestore(&chip
->lock
, flags
);
690 static int snd_cs4231_timer_stop(struct snd_timer
*timer
)
693 struct snd_cs4231
*chip
= snd_timer_chip(timer
);
695 spin_lock_irqsave(&chip
->lock
, flags
);
696 chip
->image
[CS4231_ALT_FEATURE_1
] &= ~CS4231_TIMER_ENABLE
;
697 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_1
,
698 chip
->image
[CS4231_ALT_FEATURE_1
]);
699 spin_unlock_irqrestore(&chip
->lock
, flags
);
704 static void __devinit
snd_cs4231_init(struct snd_cs4231
*chip
)
708 snd_cs4231_mce_down(chip
);
710 #ifdef SNDRV_DEBUG_MCE
711 snd_printdd("init: (1)\n");
713 snd_cs4231_mce_up(chip
);
714 spin_lock_irqsave(&chip
->lock
, flags
);
715 chip
->image
[CS4231_IFACE_CTRL
] &= ~(CS4231_PLAYBACK_ENABLE
|
716 CS4231_PLAYBACK_PIO
|
717 CS4231_RECORD_ENABLE
|
720 chip
->image
[CS4231_IFACE_CTRL
] |= CS4231_AUTOCALIB
;
721 snd_cs4231_out(chip
, CS4231_IFACE_CTRL
, chip
->image
[CS4231_IFACE_CTRL
]);
722 spin_unlock_irqrestore(&chip
->lock
, flags
);
723 snd_cs4231_mce_down(chip
);
725 #ifdef SNDRV_DEBUG_MCE
726 snd_printdd("init: (2)\n");
729 snd_cs4231_mce_up(chip
);
730 spin_lock_irqsave(&chip
->lock
, flags
);
731 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_1
,
732 chip
->image
[CS4231_ALT_FEATURE_1
]);
733 spin_unlock_irqrestore(&chip
->lock
, flags
);
734 snd_cs4231_mce_down(chip
);
736 #ifdef SNDRV_DEBUG_MCE
737 snd_printdd("init: (3) - afei = 0x%x\n",
738 chip
->image
[CS4231_ALT_FEATURE_1
]);
741 spin_lock_irqsave(&chip
->lock
, flags
);
742 snd_cs4231_out(chip
, CS4231_ALT_FEATURE_2
,
743 chip
->image
[CS4231_ALT_FEATURE_2
]);
744 spin_unlock_irqrestore(&chip
->lock
, flags
);
746 snd_cs4231_mce_up(chip
);
747 spin_lock_irqsave(&chip
->lock
, flags
);
748 snd_cs4231_out(chip
, CS4231_PLAYBK_FORMAT
,
749 chip
->image
[CS4231_PLAYBK_FORMAT
]);
750 spin_unlock_irqrestore(&chip
->lock
, flags
);
751 snd_cs4231_mce_down(chip
);
753 #ifdef SNDRV_DEBUG_MCE
754 snd_printdd("init: (4)\n");
757 snd_cs4231_mce_up(chip
);
758 spin_lock_irqsave(&chip
->lock
, flags
);
759 snd_cs4231_out(chip
, CS4231_REC_FORMAT
, chip
->image
[CS4231_REC_FORMAT
]);
760 spin_unlock_irqrestore(&chip
->lock
, flags
);
761 snd_cs4231_mce_down(chip
);
763 #ifdef SNDRV_DEBUG_MCE
764 snd_printdd("init: (5)\n");
768 static int snd_cs4231_open(struct snd_cs4231
*chip
, unsigned int mode
)
772 mutex_lock(&chip
->open_mutex
);
773 if ((chip
->mode
& mode
)) {
774 mutex_unlock(&chip
->open_mutex
);
777 if (chip
->mode
& CS4231_MODE_OPEN
) {
779 mutex_unlock(&chip
->open_mutex
);
782 /* ok. now enable and ack CODEC IRQ */
783 spin_lock_irqsave(&chip
->lock
, flags
);
784 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, CS4231_PLAYBACK_IRQ
|
787 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, 0);
788 __cs4231_writeb(chip
, 0, CS4231U(chip
, STATUS
)); /* clear IRQ */
789 __cs4231_writeb(chip
, 0, CS4231U(chip
, STATUS
)); /* clear IRQ */
791 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, CS4231_PLAYBACK_IRQ
|
794 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, 0);
796 spin_unlock_irqrestore(&chip
->lock
, flags
);
799 mutex_unlock(&chip
->open_mutex
);
803 static void snd_cs4231_close(struct snd_cs4231
*chip
, unsigned int mode
)
807 mutex_lock(&chip
->open_mutex
);
809 if (chip
->mode
& CS4231_MODE_OPEN
) {
810 mutex_unlock(&chip
->open_mutex
);
813 snd_cs4231_calibrate_mute(chip
, 1);
816 spin_lock_irqsave(&chip
->lock
, flags
);
817 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, 0);
818 __cs4231_writeb(chip
, 0, CS4231U(chip
, STATUS
)); /* clear IRQ */
819 __cs4231_writeb(chip
, 0, CS4231U(chip
, STATUS
)); /* clear IRQ */
821 /* now disable record & playback */
823 if (chip
->image
[CS4231_IFACE_CTRL
] &
824 (CS4231_PLAYBACK_ENABLE
| CS4231_PLAYBACK_PIO
|
825 CS4231_RECORD_ENABLE
| CS4231_RECORD_PIO
)) {
826 spin_unlock_irqrestore(&chip
->lock
, flags
);
827 snd_cs4231_mce_up(chip
);
828 spin_lock_irqsave(&chip
->lock
, flags
);
829 chip
->image
[CS4231_IFACE_CTRL
] &=
830 ~(CS4231_PLAYBACK_ENABLE
| CS4231_PLAYBACK_PIO
|
831 CS4231_RECORD_ENABLE
| CS4231_RECORD_PIO
);
832 snd_cs4231_out(chip
, CS4231_IFACE_CTRL
,
833 chip
->image
[CS4231_IFACE_CTRL
]);
834 spin_unlock_irqrestore(&chip
->lock
, flags
);
835 snd_cs4231_mce_down(chip
);
836 spin_lock_irqsave(&chip
->lock
, flags
);
839 /* clear IRQ again */
840 snd_cs4231_out(chip
, CS4231_IRQ_STATUS
, 0);
841 __cs4231_writeb(chip
, 0, CS4231U(chip
, STATUS
)); /* clear IRQ */
842 __cs4231_writeb(chip
, 0, CS4231U(chip
, STATUS
)); /* clear IRQ */
843 spin_unlock_irqrestore(&chip
->lock
, flags
);
845 snd_cs4231_calibrate_mute(chip
, 0);
848 mutex_unlock(&chip
->open_mutex
);
855 static int snd_cs4231_timer_open(struct snd_timer
*timer
)
857 struct snd_cs4231
*chip
= snd_timer_chip(timer
);
858 snd_cs4231_open(chip
, CS4231_MODE_TIMER
);
862 static int snd_cs4231_timer_close(struct snd_timer
*timer
)
864 struct snd_cs4231
*chip
= snd_timer_chip(timer
);
865 snd_cs4231_close(chip
, CS4231_MODE_TIMER
);
869 static struct snd_timer_hardware snd_cs4231_timer_table
= {
870 .flags
= SNDRV_TIMER_HW_AUTO
,
873 .open
= snd_cs4231_timer_open
,
874 .close
= snd_cs4231_timer_close
,
875 .c_resolution
= snd_cs4231_timer_resolution
,
876 .start
= snd_cs4231_timer_start
,
877 .stop
= snd_cs4231_timer_stop
,
881 * ok.. exported functions..
884 static int snd_cs4231_playback_hw_params(struct snd_pcm_substream
*substream
,
885 struct snd_pcm_hw_params
*hw_params
)
887 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
888 unsigned char new_pdfr
;
891 err
= snd_pcm_lib_malloc_pages(substream
,
892 params_buffer_bytes(hw_params
));
895 new_pdfr
= snd_cs4231_get_format(chip
, params_format(hw_params
),
896 params_channels(hw_params
)) |
897 snd_cs4231_get_rate(params_rate(hw_params
));
898 snd_cs4231_playback_format(chip
, hw_params
, new_pdfr
);
903 static int snd_cs4231_playback_prepare(struct snd_pcm_substream
*substream
)
905 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
906 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
909 spin_lock_irqsave(&chip
->lock
, flags
);
911 chip
->image
[CS4231_IFACE_CTRL
] &= ~(CS4231_PLAYBACK_ENABLE
|
912 CS4231_PLAYBACK_PIO
);
914 BUG_ON(runtime
->period_size
> 0xffff + 1);
916 chip
->p_periods_sent
= 0;
917 spin_unlock_irqrestore(&chip
->lock
, flags
);
922 static int snd_cs4231_capture_hw_params(struct snd_pcm_substream
*substream
,
923 struct snd_pcm_hw_params
*hw_params
)
925 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
926 unsigned char new_cdfr
;
929 err
= snd_pcm_lib_malloc_pages(substream
,
930 params_buffer_bytes(hw_params
));
933 new_cdfr
= snd_cs4231_get_format(chip
, params_format(hw_params
),
934 params_channels(hw_params
)) |
935 snd_cs4231_get_rate(params_rate(hw_params
));
936 snd_cs4231_capture_format(chip
, hw_params
, new_cdfr
);
941 static int snd_cs4231_capture_prepare(struct snd_pcm_substream
*substream
)
943 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
946 spin_lock_irqsave(&chip
->lock
, flags
);
947 chip
->image
[CS4231_IFACE_CTRL
] &= ~(CS4231_RECORD_ENABLE
|
951 chip
->c_periods_sent
= 0;
952 spin_unlock_irqrestore(&chip
->lock
, flags
);
957 static void snd_cs4231_overrange(struct snd_cs4231
*chip
)
962 spin_lock_irqsave(&chip
->lock
, flags
);
963 res
= snd_cs4231_in(chip
, CS4231_TEST_INIT
);
964 spin_unlock_irqrestore(&chip
->lock
, flags
);
966 /* detect overrange only above 0dB; may be user selectable? */
967 if (res
& (0x08 | 0x02))
968 chip
->capture_substream
->runtime
->overrange
++;
971 static void snd_cs4231_play_callback(struct snd_cs4231
*chip
)
973 if (chip
->image
[CS4231_IFACE_CTRL
] & CS4231_PLAYBACK_ENABLE
) {
974 snd_pcm_period_elapsed(chip
->playback_substream
);
975 snd_cs4231_advance_dma(&chip
->p_dma
, chip
->playback_substream
,
976 &chip
->p_periods_sent
);
980 static void snd_cs4231_capture_callback(struct snd_cs4231
*chip
)
982 if (chip
->image
[CS4231_IFACE_CTRL
] & CS4231_RECORD_ENABLE
) {
983 snd_pcm_period_elapsed(chip
->capture_substream
);
984 snd_cs4231_advance_dma(&chip
->c_dma
, chip
->capture_substream
,
985 &chip
->c_periods_sent
);
989 static snd_pcm_uframes_t
snd_cs4231_playback_pointer(
990 struct snd_pcm_substream
*substream
)
992 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
993 struct cs4231_dma_control
*dma_cont
= &chip
->p_dma
;
996 if (!(chip
->image
[CS4231_IFACE_CTRL
] & CS4231_PLAYBACK_ENABLE
))
998 ptr
= dma_cont
->address(dma_cont
);
1000 ptr
-= substream
->runtime
->dma_addr
;
1002 return bytes_to_frames(substream
->runtime
, ptr
);
1005 static snd_pcm_uframes_t
snd_cs4231_capture_pointer(
1006 struct snd_pcm_substream
*substream
)
1008 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
1009 struct cs4231_dma_control
*dma_cont
= &chip
->c_dma
;
1012 if (!(chip
->image
[CS4231_IFACE_CTRL
] & CS4231_RECORD_ENABLE
))
1014 ptr
= dma_cont
->address(dma_cont
);
1016 ptr
-= substream
->runtime
->dma_addr
;
1018 return bytes_to_frames(substream
->runtime
, ptr
);
1021 static int __devinit
snd_cs4231_probe(struct snd_cs4231
*chip
)
1023 unsigned long flags
;
1029 for (i
= 0; i
< 50; i
++) {
1031 if (__cs4231_readb(chip
, CS4231U(chip
, REGSEL
)) & CS4231_INIT
)
1034 spin_lock_irqsave(&chip
->lock
, flags
);
1035 snd_cs4231_out(chip
, CS4231_MISC_INFO
, CS4231_MODE2
);
1036 id
= snd_cs4231_in(chip
, CS4231_MISC_INFO
) & 0x0f;
1037 vers
= snd_cs4231_in(chip
, CS4231_VERSION
);
1038 spin_unlock_irqrestore(&chip
->lock
, flags
);
1040 break; /* this is valid value */
1043 snd_printdd("cs4231: port = %p, id = 0x%x\n", chip
->port
, id
);
1045 return -ENODEV
; /* no valid device found */
1047 spin_lock_irqsave(&chip
->lock
, flags
);
1049 /* clear any pendings IRQ */
1050 __cs4231_readb(chip
, CS4231U(chip
, STATUS
));
1051 __cs4231_writeb(chip
, 0, CS4231U(chip
, STATUS
));
1054 spin_unlock_irqrestore(&chip
->lock
, flags
);
1056 chip
->image
[CS4231_MISC_INFO
] = CS4231_MODE2
;
1057 chip
->image
[CS4231_IFACE_CTRL
] =
1058 chip
->image
[CS4231_IFACE_CTRL
] & ~CS4231_SINGLE_DMA
;
1059 chip
->image
[CS4231_ALT_FEATURE_1
] = 0x80;
1060 chip
->image
[CS4231_ALT_FEATURE_2
] = 0x01;
1062 chip
->image
[CS4231_ALT_FEATURE_2
] |= 0x02;
1064 ptr
= (unsigned char *) &chip
->image
;
1066 snd_cs4231_mce_down(chip
);
1068 spin_lock_irqsave(&chip
->lock
, flags
);
1070 for (i
= 0; i
< 32; i
++) /* ok.. fill all CS4231 registers */
1071 snd_cs4231_out(chip
, i
, *ptr
++);
1073 spin_unlock_irqrestore(&chip
->lock
, flags
);
1075 snd_cs4231_mce_up(chip
);
1077 snd_cs4231_mce_down(chip
);
1081 return 0; /* all things are ok.. */
1084 static struct snd_pcm_hardware snd_cs4231_playback
= {
1085 .info
= SNDRV_PCM_INFO_MMAP
|
1086 SNDRV_PCM_INFO_INTERLEAVED
|
1087 SNDRV_PCM_INFO_MMAP_VALID
|
1088 SNDRV_PCM_INFO_SYNC_START
,
1089 .formats
= SNDRV_PCM_FMTBIT_MU_LAW
|
1090 SNDRV_PCM_FMTBIT_A_LAW
|
1091 SNDRV_PCM_FMTBIT_IMA_ADPCM
|
1092 SNDRV_PCM_FMTBIT_U8
|
1093 SNDRV_PCM_FMTBIT_S16_LE
|
1094 SNDRV_PCM_FMTBIT_S16_BE
,
1095 .rates
= SNDRV_PCM_RATE_KNOT
|
1096 SNDRV_PCM_RATE_8000_48000
,
1101 .buffer_bytes_max
= 32 * 1024,
1102 .period_bytes_min
= 64,
1103 .period_bytes_max
= 32 * 1024,
1105 .periods_max
= 1024,
1108 static struct snd_pcm_hardware snd_cs4231_capture
= {
1109 .info
= SNDRV_PCM_INFO_MMAP
|
1110 SNDRV_PCM_INFO_INTERLEAVED
|
1111 SNDRV_PCM_INFO_MMAP_VALID
|
1112 SNDRV_PCM_INFO_SYNC_START
,
1113 .formats
= SNDRV_PCM_FMTBIT_MU_LAW
|
1114 SNDRV_PCM_FMTBIT_A_LAW
|
1115 SNDRV_PCM_FMTBIT_IMA_ADPCM
|
1116 SNDRV_PCM_FMTBIT_U8
|
1117 SNDRV_PCM_FMTBIT_S16_LE
|
1118 SNDRV_PCM_FMTBIT_S16_BE
,
1119 .rates
= SNDRV_PCM_RATE_KNOT
|
1120 SNDRV_PCM_RATE_8000_48000
,
1125 .buffer_bytes_max
= 32 * 1024,
1126 .period_bytes_min
= 64,
1127 .period_bytes_max
= 32 * 1024,
1129 .periods_max
= 1024,
1132 static int snd_cs4231_playback_open(struct snd_pcm_substream
*substream
)
1134 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
1135 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1138 runtime
->hw
= snd_cs4231_playback
;
1140 err
= snd_cs4231_open(chip
, CS4231_MODE_PLAY
);
1142 snd_free_pages(runtime
->dma_area
, runtime
->dma_bytes
);
1145 chip
->playback_substream
= substream
;
1146 chip
->p_periods_sent
= 0;
1147 snd_pcm_set_sync(substream
);
1148 snd_cs4231_xrate(runtime
);
1153 static int snd_cs4231_capture_open(struct snd_pcm_substream
*substream
)
1155 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
1156 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1159 runtime
->hw
= snd_cs4231_capture
;
1161 err
= snd_cs4231_open(chip
, CS4231_MODE_RECORD
);
1163 snd_free_pages(runtime
->dma_area
, runtime
->dma_bytes
);
1166 chip
->capture_substream
= substream
;
1167 chip
->c_periods_sent
= 0;
1168 snd_pcm_set_sync(substream
);
1169 snd_cs4231_xrate(runtime
);
1174 static int snd_cs4231_playback_close(struct snd_pcm_substream
*substream
)
1176 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
1178 snd_cs4231_close(chip
, CS4231_MODE_PLAY
);
1179 chip
->playback_substream
= NULL
;
1184 static int snd_cs4231_capture_close(struct snd_pcm_substream
*substream
)
1186 struct snd_cs4231
*chip
= snd_pcm_substream_chip(substream
);
1188 snd_cs4231_close(chip
, CS4231_MODE_RECORD
);
1189 chip
->capture_substream
= NULL
;
1195 static struct snd_pcm_ops snd_cs4231_playback_ops
= {
1196 .open
= snd_cs4231_playback_open
,
1197 .close
= snd_cs4231_playback_close
,
1198 .ioctl
= snd_pcm_lib_ioctl
,
1199 .hw_params
= snd_cs4231_playback_hw_params
,
1200 .hw_free
= snd_pcm_lib_free_pages
,
1201 .prepare
= snd_cs4231_playback_prepare
,
1202 .trigger
= snd_cs4231_trigger
,
1203 .pointer
= snd_cs4231_playback_pointer
,
1206 static struct snd_pcm_ops snd_cs4231_capture_ops
= {
1207 .open
= snd_cs4231_capture_open
,
1208 .close
= snd_cs4231_capture_close
,
1209 .ioctl
= snd_pcm_lib_ioctl
,
1210 .hw_params
= snd_cs4231_capture_hw_params
,
1211 .hw_free
= snd_pcm_lib_free_pages
,
1212 .prepare
= snd_cs4231_capture_prepare
,
1213 .trigger
= snd_cs4231_trigger
,
1214 .pointer
= snd_cs4231_capture_pointer
,
1217 static int __devinit
snd_cs4231_pcm(struct snd_card
*card
)
1219 struct snd_cs4231
*chip
= card
->private_data
;
1220 struct snd_pcm
*pcm
;
1223 err
= snd_pcm_new(card
, "CS4231", 0, 1, 1, &pcm
);
1227 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
1228 &snd_cs4231_playback_ops
);
1229 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
1230 &snd_cs4231_capture_ops
);
1233 pcm
->private_data
= chip
;
1234 pcm
->info_flags
= SNDRV_PCM_INFO_JOINT_DUPLEX
;
1235 strcpy(pcm
->name
, "CS4231");
1237 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
1239 64 * 1024, 128 * 1024);
1246 static int __devinit
snd_cs4231_timer(struct snd_card
*card
)
1248 struct snd_cs4231
*chip
= card
->private_data
;
1249 struct snd_timer
*timer
;
1250 struct snd_timer_id tid
;
1253 /* Timer initialization */
1254 tid
.dev_class
= SNDRV_TIMER_CLASS_CARD
;
1255 tid
.dev_sclass
= SNDRV_TIMER_SCLASS_NONE
;
1256 tid
.card
= card
->number
;
1259 err
= snd_timer_new(card
, "CS4231", &tid
, &timer
);
1262 strcpy(timer
->name
, "CS4231");
1263 timer
->private_data
= chip
;
1264 timer
->hw
= snd_cs4231_timer_table
;
1265 chip
->timer
= timer
;
1274 static int snd_cs4231_info_mux(struct snd_kcontrol
*kcontrol
,
1275 struct snd_ctl_elem_info
*uinfo
)
1277 static char *texts
[4] = {
1278 "Line", "CD", "Mic", "Mix"
1281 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1283 uinfo
->value
.enumerated
.items
= 4;
1284 if (uinfo
->value
.enumerated
.item
> 3)
1285 uinfo
->value
.enumerated
.item
= 3;
1286 strcpy(uinfo
->value
.enumerated
.name
,
1287 texts
[uinfo
->value
.enumerated
.item
]);
1292 static int snd_cs4231_get_mux(struct snd_kcontrol
*kcontrol
,
1293 struct snd_ctl_elem_value
*ucontrol
)
1295 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1296 unsigned long flags
;
1298 spin_lock_irqsave(&chip
->lock
, flags
);
1299 ucontrol
->value
.enumerated
.item
[0] =
1300 (chip
->image
[CS4231_LEFT_INPUT
] & CS4231_MIXS_ALL
) >> 6;
1301 ucontrol
->value
.enumerated
.item
[1] =
1302 (chip
->image
[CS4231_RIGHT_INPUT
] & CS4231_MIXS_ALL
) >> 6;
1303 spin_unlock_irqrestore(&chip
->lock
, flags
);
1308 static int snd_cs4231_put_mux(struct snd_kcontrol
*kcontrol
,
1309 struct snd_ctl_elem_value
*ucontrol
)
1311 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1312 unsigned long flags
;
1313 unsigned short left
, right
;
1316 if (ucontrol
->value
.enumerated
.item
[0] > 3 ||
1317 ucontrol
->value
.enumerated
.item
[1] > 3)
1319 left
= ucontrol
->value
.enumerated
.item
[0] << 6;
1320 right
= ucontrol
->value
.enumerated
.item
[1] << 6;
1322 spin_lock_irqsave(&chip
->lock
, flags
);
1324 left
= (chip
->image
[CS4231_LEFT_INPUT
] & ~CS4231_MIXS_ALL
) | left
;
1325 right
= (chip
->image
[CS4231_RIGHT_INPUT
] & ~CS4231_MIXS_ALL
) | right
;
1326 change
= left
!= chip
->image
[CS4231_LEFT_INPUT
] ||
1327 right
!= chip
->image
[CS4231_RIGHT_INPUT
];
1328 snd_cs4231_out(chip
, CS4231_LEFT_INPUT
, left
);
1329 snd_cs4231_out(chip
, CS4231_RIGHT_INPUT
, right
);
1331 spin_unlock_irqrestore(&chip
->lock
, flags
);
1336 static int snd_cs4231_info_single(struct snd_kcontrol
*kcontrol
,
1337 struct snd_ctl_elem_info
*uinfo
)
1339 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1341 uinfo
->type
= (mask
== 1) ?
1342 SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1344 uinfo
->value
.integer
.min
= 0;
1345 uinfo
->value
.integer
.max
= mask
;
1350 static int snd_cs4231_get_single(struct snd_kcontrol
*kcontrol
,
1351 struct snd_ctl_elem_value
*ucontrol
)
1353 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1354 unsigned long flags
;
1355 int reg
= kcontrol
->private_value
& 0xff;
1356 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1357 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1358 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1360 spin_lock_irqsave(&chip
->lock
, flags
);
1362 ucontrol
->value
.integer
.value
[0] = (chip
->image
[reg
] >> shift
) & mask
;
1364 spin_unlock_irqrestore(&chip
->lock
, flags
);
1367 ucontrol
->value
.integer
.value
[0] =
1368 (mask
- ucontrol
->value
.integer
.value
[0]);
1373 static int snd_cs4231_put_single(struct snd_kcontrol
*kcontrol
,
1374 struct snd_ctl_elem_value
*ucontrol
)
1376 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1377 unsigned long flags
;
1378 int reg
= kcontrol
->private_value
& 0xff;
1379 int shift
= (kcontrol
->private_value
>> 8) & 0xff;
1380 int mask
= (kcontrol
->private_value
>> 16) & 0xff;
1381 int invert
= (kcontrol
->private_value
>> 24) & 0xff;
1385 val
= (ucontrol
->value
.integer
.value
[0] & mask
);
1390 spin_lock_irqsave(&chip
->lock
, flags
);
1392 val
= (chip
->image
[reg
] & ~(mask
<< shift
)) | val
;
1393 change
= val
!= chip
->image
[reg
];
1394 snd_cs4231_out(chip
, reg
, val
);
1396 spin_unlock_irqrestore(&chip
->lock
, flags
);
1401 static int snd_cs4231_info_double(struct snd_kcontrol
*kcontrol
,
1402 struct snd_ctl_elem_info
*uinfo
)
1404 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1406 uinfo
->type
= mask
== 1 ?
1407 SNDRV_CTL_ELEM_TYPE_BOOLEAN
: SNDRV_CTL_ELEM_TYPE_INTEGER
;
1409 uinfo
->value
.integer
.min
= 0;
1410 uinfo
->value
.integer
.max
= mask
;
1415 static int snd_cs4231_get_double(struct snd_kcontrol
*kcontrol
,
1416 struct snd_ctl_elem_value
*ucontrol
)
1418 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1419 unsigned long flags
;
1420 int left_reg
= kcontrol
->private_value
& 0xff;
1421 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1422 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1423 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1424 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1425 int invert
= (kcontrol
->private_value
>> 22) & 1;
1427 spin_lock_irqsave(&chip
->lock
, flags
);
1429 ucontrol
->value
.integer
.value
[0] =
1430 (chip
->image
[left_reg
] >> shift_left
) & mask
;
1431 ucontrol
->value
.integer
.value
[1] =
1432 (chip
->image
[right_reg
] >> shift_right
) & mask
;
1434 spin_unlock_irqrestore(&chip
->lock
, flags
);
1437 ucontrol
->value
.integer
.value
[0] =
1438 (mask
- ucontrol
->value
.integer
.value
[0]);
1439 ucontrol
->value
.integer
.value
[1] =
1440 (mask
- ucontrol
->value
.integer
.value
[1]);
1446 static int snd_cs4231_put_double(struct snd_kcontrol
*kcontrol
,
1447 struct snd_ctl_elem_value
*ucontrol
)
1449 struct snd_cs4231
*chip
= snd_kcontrol_chip(kcontrol
);
1450 unsigned long flags
;
1451 int left_reg
= kcontrol
->private_value
& 0xff;
1452 int right_reg
= (kcontrol
->private_value
>> 8) & 0xff;
1453 int shift_left
= (kcontrol
->private_value
>> 16) & 0x07;
1454 int shift_right
= (kcontrol
->private_value
>> 19) & 0x07;
1455 int mask
= (kcontrol
->private_value
>> 24) & 0xff;
1456 int invert
= (kcontrol
->private_value
>> 22) & 1;
1458 unsigned short val1
, val2
;
1460 val1
= ucontrol
->value
.integer
.value
[0] & mask
;
1461 val2
= ucontrol
->value
.integer
.value
[1] & mask
;
1466 val1
<<= shift_left
;
1467 val2
<<= shift_right
;
1469 spin_lock_irqsave(&chip
->lock
, flags
);
1471 val1
= (chip
->image
[left_reg
] & ~(mask
<< shift_left
)) | val1
;
1472 val2
= (chip
->image
[right_reg
] & ~(mask
<< shift_right
)) | val2
;
1473 change
= val1
!= chip
->image
[left_reg
];
1474 change
|= val2
!= chip
->image
[right_reg
];
1475 snd_cs4231_out(chip
, left_reg
, val1
);
1476 snd_cs4231_out(chip
, right_reg
, val2
);
1478 spin_unlock_irqrestore(&chip
->lock
, flags
);
1483 #define CS4231_SINGLE(xname, xindex, reg, shift, mask, invert) \
1484 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .index = (xindex), \
1485 .info = snd_cs4231_info_single, \
1486 .get = snd_cs4231_get_single, .put = snd_cs4231_put_single, \
1487 .private_value = (reg) | ((shift) << 8) | ((mask) << 16) | ((invert) << 24) }
1489 #define CS4231_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, \
1490 shift_right, mask, invert) \
1491 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .index = (xindex), \
1492 .info = snd_cs4231_info_double, \
1493 .get = snd_cs4231_get_double, .put = snd_cs4231_put_double, \
1494 .private_value = (left_reg) | ((right_reg) << 8) | ((shift_left) << 16) | \
1495 ((shift_right) << 19) | ((mask) << 24) | ((invert) << 22) }
1497 static struct snd_kcontrol_new snd_cs4231_controls
[] __devinitdata
= {
1498 CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT
,
1499 CS4231_RIGHT_OUTPUT
, 7, 7, 1, 1),
1500 CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT
,
1501 CS4231_RIGHT_OUTPUT
, 0, 0, 63, 1),
1502 CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN
,
1503 CS4231_RIGHT_LINE_IN
, 7, 7, 1, 1),
1504 CS4231_DOUBLE("Line Playback Volume", 0, CS4231_LEFT_LINE_IN
,
1505 CS4231_RIGHT_LINE_IN
, 0, 0, 31, 1),
1506 CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT
,
1507 CS4231_AUX1_RIGHT_INPUT
, 7, 7, 1, 1),
1508 CS4231_DOUBLE("Aux Playback Volume", 0, CS4231_AUX1_LEFT_INPUT
,
1509 CS4231_AUX1_RIGHT_INPUT
, 0, 0, 31, 1),
1510 CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT
,
1511 CS4231_AUX2_RIGHT_INPUT
, 7, 7, 1, 1),
1512 CS4231_DOUBLE("Aux Playback Volume", 1, CS4231_AUX2_LEFT_INPUT
,
1513 CS4231_AUX2_RIGHT_INPUT
, 0, 0, 31, 1),
1514 CS4231_SINGLE("Mono Playback Switch", 0, CS4231_MONO_CTRL
, 7, 1, 1),
1515 CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL
, 0, 15, 1),
1516 CS4231_SINGLE("Mono Output Playback Switch", 0, CS4231_MONO_CTRL
, 6, 1, 1),
1517 CS4231_SINGLE("Mono Output Playback Bypass", 0, CS4231_MONO_CTRL
, 5, 1, 0),
1518 CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT
, CS4231_RIGHT_INPUT
, 0, 0,
1521 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
1522 .name
= "Capture Source",
1523 .info
= snd_cs4231_info_mux
,
1524 .get
= snd_cs4231_get_mux
,
1525 .put
= snd_cs4231_put_mux
,
1527 CS4231_DOUBLE("Mic Boost", 0, CS4231_LEFT_INPUT
, CS4231_RIGHT_INPUT
, 5, 5,
1529 CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK
, 0, 1, 0),
1530 CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK
, 2, 63, 1),
1531 /* SPARC specific uses of XCTL{0,1} general purpose outputs. */
1532 CS4231_SINGLE("Line Out Switch", 0, CS4231_PIN_CTRL
, 6, 1, 1),
1533 CS4231_SINGLE("Headphone Out Switch", 0, CS4231_PIN_CTRL
, 7, 1, 1)
1536 static int __devinit
snd_cs4231_mixer(struct snd_card
*card
)
1538 struct snd_cs4231
*chip
= card
->private_data
;
1541 if (snd_BUG_ON(!chip
|| !chip
->pcm
))
1544 strcpy(card
->mixername
, chip
->pcm
->name
);
1546 for (idx
= 0; idx
< ARRAY_SIZE(snd_cs4231_controls
); idx
++) {
1547 err
= snd_ctl_add(card
,
1548 snd_ctl_new1(&snd_cs4231_controls
[idx
], chip
));
1557 static int __devinit
cs4231_attach_begin(struct snd_card
**rcard
)
1559 struct snd_card
*card
;
1560 struct snd_cs4231
*chip
;
1565 if (dev
>= SNDRV_CARDS
)
1573 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
,
1574 sizeof(struct snd_cs4231
), &card
);
1578 strcpy(card
->driver
, "CS4231");
1579 strcpy(card
->shortname
, "Sun CS4231");
1581 chip
= card
->private_data
;
1588 static int __devinit
cs4231_attach_finish(struct snd_card
*card
)
1590 struct snd_cs4231
*chip
= card
->private_data
;
1593 err
= snd_cs4231_pcm(card
);
1597 err
= snd_cs4231_mixer(card
);
1601 err
= snd_cs4231_timer(card
);
1605 err
= snd_card_register(card
);
1609 dev_set_drvdata(&chip
->op
->dev
, chip
);
1615 snd_card_free(card
);
1621 static irqreturn_t
snd_cs4231_sbus_interrupt(int irq
, void *dev_id
)
1623 unsigned long flags
;
1624 unsigned char status
;
1626 struct snd_cs4231
*chip
= dev_id
;
1628 /*This is IRQ is not raised by the cs4231*/
1629 if (!(__cs4231_readb(chip
, CS4231U(chip
, STATUS
)) & CS4231_GLOBALIRQ
))
1632 /* ACK the APC interrupt. */
1633 csr
= sbus_readl(chip
->port
+ APCCSR
);
1635 sbus_writel(csr
, chip
->port
+ APCCSR
);
1637 if ((csr
& APC_PDMA_READY
) &&
1638 (csr
& APC_PLAY_INT
) &&
1639 (csr
& APC_XINT_PNVA
) &&
1640 !(csr
& APC_XINT_EMPT
))
1641 snd_cs4231_play_callback(chip
);
1643 if ((csr
& APC_CDMA_READY
) &&
1644 (csr
& APC_CAPT_INT
) &&
1645 (csr
& APC_XINT_CNVA
) &&
1646 !(csr
& APC_XINT_EMPT
))
1647 snd_cs4231_capture_callback(chip
);
1649 status
= snd_cs4231_in(chip
, CS4231_IRQ_STATUS
);
1651 if (status
& CS4231_TIMER_IRQ
) {
1653 snd_timer_interrupt(chip
->timer
, chip
->timer
->sticks
);
1656 if ((status
& CS4231_RECORD_IRQ
) && (csr
& APC_CDMA_READY
))
1657 snd_cs4231_overrange(chip
);
1659 /* ACK the CS4231 interrupt. */
1660 spin_lock_irqsave(&chip
->lock
, flags
);
1661 snd_cs4231_outm(chip
, CS4231_IRQ_STATUS
, ~CS4231_ALL_IRQS
| ~status
, 0);
1662 spin_unlock_irqrestore(&chip
->lock
, flags
);
1671 static int sbus_dma_request(struct cs4231_dma_control
*dma_cont
,
1672 dma_addr_t bus_addr
, size_t len
)
1674 unsigned long flags
;
1677 struct sbus_dma_info
*base
= &dma_cont
->sbus_info
;
1679 if (len
>= (1 << 24))
1681 spin_lock_irqsave(&base
->lock
, flags
);
1682 csr
= sbus_readl(base
->regs
+ APCCSR
);
1684 test
= APC_CDMA_READY
;
1685 if (base
->dir
== APC_PLAY
)
1686 test
= APC_PDMA_READY
;
1690 test
= APC_XINT_CNVA
;
1691 if (base
->dir
== APC_PLAY
)
1692 test
= APC_XINT_PNVA
;
1696 sbus_writel(bus_addr
, base
->regs
+ base
->dir
+ APCNVA
);
1697 sbus_writel(len
, base
->regs
+ base
->dir
+ APCNC
);
1699 spin_unlock_irqrestore(&base
->lock
, flags
);
1703 static void sbus_dma_prepare(struct cs4231_dma_control
*dma_cont
, int d
)
1705 unsigned long flags
;
1707 struct sbus_dma_info
*base
= &dma_cont
->sbus_info
;
1709 spin_lock_irqsave(&base
->lock
, flags
);
1710 csr
= sbus_readl(base
->regs
+ APCCSR
);
1711 test
= APC_GENL_INT
| APC_PLAY_INT
| APC_XINT_ENA
|
1712 APC_XINT_PLAY
| APC_XINT_PEMP
| APC_XINT_GENL
|
1714 if (base
->dir
== APC_RECORD
)
1715 test
= APC_GENL_INT
| APC_CAPT_INT
| APC_XINT_ENA
|
1716 APC_XINT_CAPT
| APC_XINT_CEMP
| APC_XINT_GENL
;
1718 sbus_writel(csr
, base
->regs
+ APCCSR
);
1719 spin_unlock_irqrestore(&base
->lock
, flags
);
1722 static void sbus_dma_enable(struct cs4231_dma_control
*dma_cont
, int on
)
1724 unsigned long flags
;
1726 struct sbus_dma_info
*base
= &dma_cont
->sbus_info
;
1728 spin_lock_irqsave(&base
->lock
, flags
);
1730 sbus_writel(0, base
->regs
+ base
->dir
+ APCNC
);
1731 sbus_writel(0, base
->regs
+ base
->dir
+ APCNVA
);
1732 if (base
->dir
== APC_PLAY
) {
1733 sbus_writel(0, base
->regs
+ base
->dir
+ APCC
);
1734 sbus_writel(0, base
->regs
+ base
->dir
+ APCVA
);
1739 csr
= sbus_readl(base
->regs
+ APCCSR
);
1741 if (base
->dir
== APC_PLAY
)
1744 csr
&= ~(APC_CPAUSE
<< shift
);
1746 csr
|= (APC_CPAUSE
<< shift
);
1747 sbus_writel(csr
, base
->regs
+ APCCSR
);
1749 csr
|= (APC_CDMA_READY
<< shift
);
1751 csr
&= ~(APC_CDMA_READY
<< shift
);
1752 sbus_writel(csr
, base
->regs
+ APCCSR
);
1754 spin_unlock_irqrestore(&base
->lock
, flags
);
1757 static unsigned int sbus_dma_addr(struct cs4231_dma_control
*dma_cont
)
1759 struct sbus_dma_info
*base
= &dma_cont
->sbus_info
;
1761 return sbus_readl(base
->regs
+ base
->dir
+ APCVA
);
1765 * Init and exit routines
1768 static int snd_cs4231_sbus_free(struct snd_cs4231
*chip
)
1770 struct platform_device
*op
= chip
->op
;
1773 free_irq(chip
->irq
[0], chip
);
1776 of_iounmap(&op
->resource
[0], chip
->port
, chip
->regs_size
);
1781 static int snd_cs4231_sbus_dev_free(struct snd_device
*device
)
1783 struct snd_cs4231
*cp
= device
->device_data
;
1785 return snd_cs4231_sbus_free(cp
);
1788 static struct snd_device_ops snd_cs4231_sbus_dev_ops
= {
1789 .dev_free
= snd_cs4231_sbus_dev_free
,
1792 static int __devinit
snd_cs4231_sbus_create(struct snd_card
*card
,
1793 struct platform_device
*op
,
1796 struct snd_cs4231
*chip
= card
->private_data
;
1799 spin_lock_init(&chip
->lock
);
1800 spin_lock_init(&chip
->c_dma
.sbus_info
.lock
);
1801 spin_lock_init(&chip
->p_dma
.sbus_info
.lock
);
1802 mutex_init(&chip
->mce_mutex
);
1803 mutex_init(&chip
->open_mutex
);
1805 chip
->regs_size
= resource_size(&op
->resource
[0]);
1806 memcpy(&chip
->image
, &snd_cs4231_original_image
,
1807 sizeof(snd_cs4231_original_image
));
1809 chip
->port
= of_ioremap(&op
->resource
[0], 0,
1810 chip
->regs_size
, "cs4231");
1812 snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev
);
1816 chip
->c_dma
.sbus_info
.regs
= chip
->port
;
1817 chip
->p_dma
.sbus_info
.regs
= chip
->port
;
1818 chip
->c_dma
.sbus_info
.dir
= APC_RECORD
;
1819 chip
->p_dma
.sbus_info
.dir
= APC_PLAY
;
1821 chip
->p_dma
.prepare
= sbus_dma_prepare
;
1822 chip
->p_dma
.enable
= sbus_dma_enable
;
1823 chip
->p_dma
.request
= sbus_dma_request
;
1824 chip
->p_dma
.address
= sbus_dma_addr
;
1826 chip
->c_dma
.prepare
= sbus_dma_prepare
;
1827 chip
->c_dma
.enable
= sbus_dma_enable
;
1828 chip
->c_dma
.request
= sbus_dma_request
;
1829 chip
->c_dma
.address
= sbus_dma_addr
;
1831 if (request_irq(op
->archdata
.irqs
[0], snd_cs4231_sbus_interrupt
,
1832 IRQF_SHARED
, "cs4231", chip
)) {
1833 snd_printdd("cs4231-%d: Unable to grab SBUS IRQ %d\n",
1834 dev
, op
->archdata
.irqs
[0]);
1835 snd_cs4231_sbus_free(chip
);
1838 chip
->irq
[0] = op
->archdata
.irqs
[0];
1840 if (snd_cs4231_probe(chip
) < 0) {
1841 snd_cs4231_sbus_free(chip
);
1844 snd_cs4231_init(chip
);
1846 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
,
1847 chip
, &snd_cs4231_sbus_dev_ops
)) < 0) {
1848 snd_cs4231_sbus_free(chip
);
1855 static int __devinit
cs4231_sbus_probe(struct platform_device
*op
, const struct of_device_id
*match
)
1857 struct resource
*rp
= &op
->resource
[0];
1858 struct snd_card
*card
;
1861 err
= cs4231_attach_begin(&card
);
1865 sprintf(card
->longname
, "%s at 0x%02lx:0x%016Lx, irq %d",
1868 (unsigned long long)rp
->start
,
1869 op
->archdata
.irqs
[0]);
1871 err
= snd_cs4231_sbus_create(card
, op
, dev
);
1873 snd_card_free(card
);
1877 return cs4231_attach_finish(card
);
1883 static void snd_cs4231_ebus_play_callback(struct ebus_dma_info
*p
, int event
,
1886 struct snd_cs4231
*chip
= cookie
;
1888 snd_cs4231_play_callback(chip
);
1891 static void snd_cs4231_ebus_capture_callback(struct ebus_dma_info
*p
,
1892 int event
, void *cookie
)
1894 struct snd_cs4231
*chip
= cookie
;
1896 snd_cs4231_capture_callback(chip
);
1903 static int _ebus_dma_request(struct cs4231_dma_control
*dma_cont
,
1904 dma_addr_t bus_addr
, size_t len
)
1906 return ebus_dma_request(&dma_cont
->ebus_info
, bus_addr
, len
);
1909 static void _ebus_dma_enable(struct cs4231_dma_control
*dma_cont
, int on
)
1911 ebus_dma_enable(&dma_cont
->ebus_info
, on
);
1914 static void _ebus_dma_prepare(struct cs4231_dma_control
*dma_cont
, int dir
)
1916 ebus_dma_prepare(&dma_cont
->ebus_info
, dir
);
1919 static unsigned int _ebus_dma_addr(struct cs4231_dma_control
*dma_cont
)
1921 return ebus_dma_addr(&dma_cont
->ebus_info
);
1925 * Init and exit routines
1928 static int snd_cs4231_ebus_free(struct snd_cs4231
*chip
)
1930 struct platform_device
*op
= chip
->op
;
1932 if (chip
->c_dma
.ebus_info
.regs
) {
1933 ebus_dma_unregister(&chip
->c_dma
.ebus_info
);
1934 of_iounmap(&op
->resource
[2], chip
->c_dma
.ebus_info
.regs
, 0x10);
1936 if (chip
->p_dma
.ebus_info
.regs
) {
1937 ebus_dma_unregister(&chip
->p_dma
.ebus_info
);
1938 of_iounmap(&op
->resource
[1], chip
->p_dma
.ebus_info
.regs
, 0x10);
1942 of_iounmap(&op
->resource
[0], chip
->port
, 0x10);
1947 static int snd_cs4231_ebus_dev_free(struct snd_device
*device
)
1949 struct snd_cs4231
*cp
= device
->device_data
;
1951 return snd_cs4231_ebus_free(cp
);
1954 static struct snd_device_ops snd_cs4231_ebus_dev_ops
= {
1955 .dev_free
= snd_cs4231_ebus_dev_free
,
1958 static int __devinit
snd_cs4231_ebus_create(struct snd_card
*card
,
1959 struct platform_device
*op
,
1962 struct snd_cs4231
*chip
= card
->private_data
;
1965 spin_lock_init(&chip
->lock
);
1966 spin_lock_init(&chip
->c_dma
.ebus_info
.lock
);
1967 spin_lock_init(&chip
->p_dma
.ebus_info
.lock
);
1968 mutex_init(&chip
->mce_mutex
);
1969 mutex_init(&chip
->open_mutex
);
1970 chip
->flags
|= CS4231_FLAG_EBUS
;
1972 memcpy(&chip
->image
, &snd_cs4231_original_image
,
1973 sizeof(snd_cs4231_original_image
));
1974 strcpy(chip
->c_dma
.ebus_info
.name
, "cs4231(capture)");
1975 chip
->c_dma
.ebus_info
.flags
= EBUS_DMA_FLAG_USE_EBDMA_HANDLER
;
1976 chip
->c_dma
.ebus_info
.callback
= snd_cs4231_ebus_capture_callback
;
1977 chip
->c_dma
.ebus_info
.client_cookie
= chip
;
1978 chip
->c_dma
.ebus_info
.irq
= op
->archdata
.irqs
[0];
1979 strcpy(chip
->p_dma
.ebus_info
.name
, "cs4231(play)");
1980 chip
->p_dma
.ebus_info
.flags
= EBUS_DMA_FLAG_USE_EBDMA_HANDLER
;
1981 chip
->p_dma
.ebus_info
.callback
= snd_cs4231_ebus_play_callback
;
1982 chip
->p_dma
.ebus_info
.client_cookie
= chip
;
1983 chip
->p_dma
.ebus_info
.irq
= op
->archdata
.irqs
[1];
1985 chip
->p_dma
.prepare
= _ebus_dma_prepare
;
1986 chip
->p_dma
.enable
= _ebus_dma_enable
;
1987 chip
->p_dma
.request
= _ebus_dma_request
;
1988 chip
->p_dma
.address
= _ebus_dma_addr
;
1990 chip
->c_dma
.prepare
= _ebus_dma_prepare
;
1991 chip
->c_dma
.enable
= _ebus_dma_enable
;
1992 chip
->c_dma
.request
= _ebus_dma_request
;
1993 chip
->c_dma
.address
= _ebus_dma_addr
;
1995 chip
->port
= of_ioremap(&op
->resource
[0], 0, 0x10, "cs4231");
1996 chip
->p_dma
.ebus_info
.regs
=
1997 of_ioremap(&op
->resource
[1], 0, 0x10, "cs4231_pdma");
1998 chip
->c_dma
.ebus_info
.regs
=
1999 of_ioremap(&op
->resource
[2], 0, 0x10, "cs4231_cdma");
2000 if (!chip
->port
|| !chip
->p_dma
.ebus_info
.regs
||
2001 !chip
->c_dma
.ebus_info
.regs
) {
2002 snd_cs4231_ebus_free(chip
);
2003 snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev
);
2007 if (ebus_dma_register(&chip
->c_dma
.ebus_info
)) {
2008 snd_cs4231_ebus_free(chip
);
2009 snd_printdd("cs4231-%d: Unable to register EBUS capture DMA\n",
2013 if (ebus_dma_irq_enable(&chip
->c_dma
.ebus_info
, 1)) {
2014 snd_cs4231_ebus_free(chip
);
2015 snd_printdd("cs4231-%d: Unable to enable EBUS capture IRQ\n",
2020 if (ebus_dma_register(&chip
->p_dma
.ebus_info
)) {
2021 snd_cs4231_ebus_free(chip
);
2022 snd_printdd("cs4231-%d: Unable to register EBUS play DMA\n",
2026 if (ebus_dma_irq_enable(&chip
->p_dma
.ebus_info
, 1)) {
2027 snd_cs4231_ebus_free(chip
);
2028 snd_printdd("cs4231-%d: Unable to enable EBUS play IRQ\n", dev
);
2032 if (snd_cs4231_probe(chip
) < 0) {
2033 snd_cs4231_ebus_free(chip
);
2036 snd_cs4231_init(chip
);
2038 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
,
2039 chip
, &snd_cs4231_ebus_dev_ops
)) < 0) {
2040 snd_cs4231_ebus_free(chip
);
2047 static int __devinit
cs4231_ebus_probe(struct platform_device
*op
, const struct of_device_id
*match
)
2049 struct snd_card
*card
;
2052 err
= cs4231_attach_begin(&card
);
2056 sprintf(card
->longname
, "%s at 0x%llx, irq %d",
2058 op
->resource
[0].start
,
2059 op
->archdata
.irqs
[0]);
2061 err
= snd_cs4231_ebus_create(card
, op
, dev
);
2063 snd_card_free(card
);
2067 return cs4231_attach_finish(card
);
2071 static int __devinit
cs4231_probe(struct platform_device
*op
, const struct of_device_id
*match
)
2074 if (!strcmp(op
->dev
.of_node
->parent
->name
, "ebus"))
2075 return cs4231_ebus_probe(op
, match
);
2078 if (!strcmp(op
->dev
.of_node
->parent
->name
, "sbus") ||
2079 !strcmp(op
->dev
.of_node
->parent
->name
, "sbi"))
2080 return cs4231_sbus_probe(op
, match
);
2085 static int __devexit
cs4231_remove(struct platform_device
*op
)
2087 struct snd_cs4231
*chip
= dev_get_drvdata(&op
->dev
);
2089 snd_card_free(chip
->card
);
2094 static const struct of_device_id cs4231_match
[] = {
2096 .name
= "SUNW,CS4231",
2100 .compatible
= "SUNW,CS4231",
2105 MODULE_DEVICE_TABLE(of
, cs4231_match
);
2107 static struct of_platform_driver cs4231_driver
= {
2110 .owner
= THIS_MODULE
,
2111 .of_match_table
= cs4231_match
,
2113 .probe
= cs4231_probe
,
2114 .remove
= __devexit_p(cs4231_remove
),
2117 static int __init
cs4231_init(void)
2119 return of_register_platform_driver(&cs4231_driver
);
2122 static void __exit
cs4231_exit(void)
2124 of_unregister_platform_driver(&cs4231_driver
);
2127 module_init(cs4231_init
);
2128 module_exit(cs4231_exit
);