1 /* $Id: cs4231.c,v 1.45 2001/03/23 08:16:13 davem Exp $
2 * drivers/sbus/audio/cs4231.c
4 * Copyright 1996, 1997, 1998, 1999 Derrick J Brashear (shadow@andrew.cmu.edu)
5 * The 4231/ebus support was written by David Miller, who didn't bother
6 * crediting himself here, so I will.
8 * Based on the AMD7930 driver:
9 * Copyright 1996 Thomas K. Dyas (tdyas@noc.rutgers.edu)
11 * This is the lowlevel driver for the CS4231 audio chip found on some
12 * sun4m and sun4u machines.
14 * This was culled from the Crystal docs on the 4231a, and the addendum they
15 * faxed me on the 4231.
16 * The APC DMA controller support unfortunately is not documented. Thanks, Sun.
19 #include <linux/config.h>
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
23 #include <linux/errno.h>
24 #include <linux/interrupt.h>
25 #include <linux/slab.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/soundcard.h>
29 #include <linux/version.h>
30 #include <linux/ioport.h>
31 #include <asm/openprom.h>
32 #include <asm/oplib.h>
33 #include <asm/system.h>
36 #include <asm/pgtable.h>
38 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE > 0x200ff && defined(CONFIG_PCI)
39 #define EB4231_SUPPORT
44 #include <asm/audioio.h>
49 #define __CS4231_ERROR
51 #define eprintk(x) printk x
56 #define tprintk(x) printk x
61 #define dprintk(x) printk x
67 static struct sparcaudio_driver drivers[MAX_DRIVERS];
68 static int num_drivers;
70 static int cs4231_record_gain(struct sparcaudio_driver *drv, int value,
71 unsigned char balance);
72 static int cs4231_play_gain(struct sparcaudio_driver *drv, int value,
73 unsigned char balance);
74 static void cs4231_ready(struct sparcaudio_driver *drv);
75 static void cs4231_playintr(struct sparcaudio_driver *drv, int);
76 static int cs4231_recintr(struct sparcaudio_driver *drv);
77 static int cs4231_output_muted(struct sparcaudio_driver *drv, int value);
78 static void cs4231_pollinput(struct sparcaudio_driver *drv);
79 static int cs4231_length_to_samplecount(struct audio_prinfo *thisdir,
81 static void cs4231_getsamplecount(struct sparcaudio_driver *drv,
82 unsigned int length, unsigned int value);
84 static void eb4231_pollinput(struct sparcaudio_driver *drv);
87 /* Serveral shorthands save typing... */
88 #define CHIP_READY() \
89 do { udelay(100); cs4231_ready(drv); udelay(1000); } while(0)
90 #define WRITE_IAR(__VAL) \
91 CS4231_WRITE8(cs4231_chip, cs4231_chip->regs + IAR, __VAL)
92 #define WRITE_IDR(__VAL) \
93 CS4231_WRITE8(cs4231_chip, cs4231_chip->regs + IDR, __VAL)
95 CS4231_READ8(cs4231_chip, cs4231_chip->regs + IAR)
97 CS4231_READ8(cs4231_chip, cs4231_chip->regs + IDR)
99 /* Enable cs4231 interrupts atomically. */
100 static void cs4231_enable_interrupts(struct sparcaudio_driver *drv)
102 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
105 tprintk(("enabling interrupts\n"));
108 if ((cs4231_chip->status & CS_STATUS_INTS_ON) == 0) {
111 cs4231_chip->status |= CS_STATUS_INTS_ON;
113 restore_flags(flags);
116 /* Disable cs4231 interrupts atomically. */
117 static void cs4231_disable_interrupts(struct sparcaudio_driver *drv)
119 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
122 tprintk(("disabling interrupts\n"));
125 if ((cs4231_chip->status & CS_STATUS_INTS_ON) != 0) {
128 cs4231_chip->status &= ~CS_STATUS_INTS_ON;
130 restore_flags(flags);
133 static void cs4231_enable_play(struct sparcaudio_driver *drv)
135 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
138 tprintk(("enabling play\n"));
142 WRITE_IDR(READ_IDR() | PEN_ENABLE);
143 restore_flags(flags);
146 static void cs4231_disable_play(struct sparcaudio_driver *drv)
148 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
151 tprintk(("disabling play\n"));
155 WRITE_IDR(READ_IDR() & PEN_DISABLE);
156 restore_flags(flags);
159 static void cs4231_enable_rec(struct sparcaudio_driver *drv)
161 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
164 tprintk(("enabling rec\n"));
168 WRITE_IDR(READ_IDR() | CEN_ENABLE);
169 restore_flags(flags);
172 static void cs4231_disable_rec(struct sparcaudio_driver *drv)
174 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
177 tprintk(("disabling rec\n"));
181 WRITE_IDR(READ_IDR() & CEN_DISABLE);
182 restore_flags(flags);
185 static struct cs4231_rates {
187 } cs4231_rate_table[] = {
188 { 5512, CS4231_DFR_5512 },
189 { 6615, CS4231_DFR_6615 },
190 { 8000, CS4231_DFR_8000 },
191 { 9600, CS4231_DFR_9600 },
192 { 11025, CS4231_DFR_11025 },
193 { 16000, CS4231_DFR_16000 },
194 { 18900, CS4231_DFR_18900 },
195 { 22050, CS4231_DFR_22050 },
196 { 27429, CS4231_DFR_27429 },
197 { 32000, CS4231_DFR_32000 },
198 { 33075, CS4231_DFR_33075 },
199 { 37800, CS4231_DFR_37800 },
200 { 44100, CS4231_DFR_44100 },
201 { 48000, CS4231_DFR_48000 }
204 #define NUM_RATES (sizeof(cs4231_rate_table) / sizeof(struct cs4231_rates))
206 static int cs4231_rate_to_bits(struct sparcaudio_driver *drv, int *value)
208 struct cs4231_rates *p = &cs4231_rate_table[0];
209 int i, wanted = *value;
211 /* We try to be nice and approximate what the user asks for. */
217 for (i = 0; i < NUM_RATES; i++, p++) {
219 if (wanted == p->speed)
222 /* If we're inbetween two entries, and neither is exact,
223 * pick the closest one.
225 if (wanted == p[1].speed)
227 if (wanted > p->speed && wanted < p[1].speed) {
230 diff1 = wanted - p->speed;
231 diff2 = p[1].speed - wanted;
241 static int cs4231_encoding_to_bits(struct sparcaudio_driver *drv, int value)
246 case AUDIO_ENCODING_ULAW:
247 set_bits = CS4231_DFR_ULAW;
249 case AUDIO_ENCODING_ALAW:
250 set_bits = CS4231_DFR_ALAW;
252 case AUDIO_ENCODING_DVI:
253 set_bits = CS4231_DFR_ADPCM;
255 case AUDIO_ENCODING_LINEARLE:
256 set_bits = CS4231_DFR_LINEARLE;
258 case AUDIO_ENCODING_LINEAR:
259 set_bits = CS4231_DFR_LINEARBE;
261 case AUDIO_ENCODING_LINEAR8:
262 set_bits = CS4231_DFR_LINEAR8;
272 static int cs4231_set_output_encoding(struct sparcaudio_driver *drv, int value)
274 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
275 int tmp_bits, set_bits;
277 tprintk(("output encoding %d\n", value));
279 set_bits = cs4231_encoding_to_bits(drv, value);
283 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x8);
284 tmp_bits = READ_IDR();
285 WRITE_IDR(CHANGE_ENCODING(tmp_bits, set_bits));
289 cs4231_chip->perchip_info.play.encoding = value;
293 dprintk(("output enc failed\n"));
297 static int cs4231_get_output_encoding(struct sparcaudio_driver *drv)
299 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
300 return cs4231_chip->perchip_info.play.encoding;
303 static int cs4231_set_input_encoding(struct sparcaudio_driver *drv, int value)
305 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
306 int tmp_bits, set_bits;
308 tprintk(("input encoding %d\n", value));
310 set_bits = cs4231_encoding_to_bits(drv, value);
314 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x1c);
315 tmp_bits = READ_IDR();
316 WRITE_IDR(CHANGE_ENCODING(tmp_bits, set_bits));
321 cs4231_chip->perchip_info.record.encoding = value;
325 dprintk(("input enc failed\n"));
329 static int cs4231_get_input_encoding(struct sparcaudio_driver *drv)
331 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
332 return cs4231_chip->perchip_info.record.encoding;
335 static int cs4231_set_output_rate(struct sparcaudio_driver *drv, int value)
337 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
338 int tmp_bits, set_bits;
340 tprintk(("output rate %d\n", value));
342 set_bits = cs4231_rate_to_bits(drv, &value);
346 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x8);
347 tmp_bits = READ_IDR();
348 WRITE_IDR(CHANGE_DFR(tmp_bits, set_bits));
353 cs4231_chip->perchip_info.play.sample_rate = value;
354 tprintk(("tmp_bits[%02x] set_bits[%02x] CHANGE_DFR[%02x]\n",
355 tmp_bits, set_bits, CHANGE_DFR(tmp_bits, set_bits)));
359 dprintk(("output rate failed\n"));
363 static int cs4231_get_output_rate(struct sparcaudio_driver *drv)
365 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
366 return cs4231_chip->perchip_info.play.sample_rate;
369 static int cs4231_set_input_rate(struct sparcaudio_driver *drv, int value)
371 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
372 int tmp_bits, set_bits;
374 tprintk(("input rate %d\n", value));
376 set_bits = cs4231_rate_to_bits(drv, &value);
380 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x1c);
381 tmp_bits = READ_IDR();
382 WRITE_IDR(CHANGE_DFR(tmp_bits, set_bits));
387 cs4231_chip->perchip_info.record.sample_rate = value;
391 dprintk(("input rate failed\n"));
395 static int cs4231_get_input_rate(struct sparcaudio_driver *drv)
397 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
398 return cs4231_chip->perchip_info.record.sample_rate;
401 /* Generically we support 4 channels. This hardware does 2 */
402 static int cs4231_set_input_channels(struct sparcaudio_driver *drv, int value)
404 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
407 tprintk(("input channels %d\n", value));
408 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x1c);
409 tmp_bits = READ_IDR();
412 WRITE_IDR(CS4231_MONO_ON(tmp_bits));
415 WRITE_IDR(CS4231_STEREO_ON(tmp_bits));
418 dprintk(("input chan failed\n"));
423 cs4231_chip->perchip_info.record.channels = value;
427 static int cs4231_get_input_channels(struct sparcaudio_driver *drv)
429 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
430 return cs4231_chip->perchip_info.record.channels;
433 /* Generically we support 4 channels. This hardware does 2 */
434 static int cs4231_set_output_channels(struct sparcaudio_driver *drv, int value)
436 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
439 tprintk(("output channels %d\n", value));
440 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x8);
441 tmp_bits = READ_IDR();
444 WRITE_IDR(CS4231_MONO_ON(tmp_bits));
447 WRITE_IDR(CS4231_STEREO_ON(tmp_bits));
450 dprintk(("output chan failed\n"));
455 cs4231_chip->perchip_info.play.channels = value;
459 static int cs4231_get_output_channels(struct sparcaudio_driver *drv)
461 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
462 return cs4231_chip->perchip_info.play.channels;
465 static int cs4231_get_input_precision(struct sparcaudio_driver *drv)
467 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
468 return cs4231_chip->perchip_info.record.precision;
471 static int cs4231_get_output_precision(struct sparcaudio_driver *drv)
473 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
474 return cs4231_chip->perchip_info.play.precision;
477 static int cs4231_set_input_precision(struct sparcaudio_driver *drv, int val)
479 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
481 cs4231_chip->perchip_info.record.precision = val;
483 return cs4231_chip->perchip_info.record.precision;
486 static int cs4231_set_output_precision(struct sparcaudio_driver *drv, int val)
488 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
490 cs4231_chip->perchip_info.play.precision = val;
492 return cs4231_chip->perchip_info.play.precision;
495 /* Wait until the auto calibration process has finished */
496 static void cs4231_ready(struct sparcaudio_driver *drv)
498 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
501 WRITE_IAR(IAR_AUTOCAL_END);
504 if (READ_IDR() != IAR_NOT_READY)
507 } while (x <= CS_TIMEOUT);
512 if (READ_IDR() != AUTOCAL_IN_PROGRESS)
515 } while (x <= CS_TIMEOUT);
518 /* Set output mute */
519 static int cs4231_output_muted(struct sparcaudio_driver *drv, int value)
521 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
522 tprintk(("in cs4231_output_muted: %d\n", value));
525 WRITE_IDR(READ_IDR() & OUTCR_UNMUTE);
527 WRITE_IDR(READ_IDR() & OUTCR_UNMUTE);
528 cs4231_chip->perchip_info.output_muted = 0;
531 WRITE_IDR(READ_IDR() | OUTCR_MUTE);
533 WRITE_IDR(READ_IDR() | OUTCR_MUTE);
534 cs4231_chip->perchip_info.output_muted = 1;
539 static int cs4231_get_output_muted(struct sparcaudio_driver *drv)
541 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
542 return cs4231_chip->perchip_info.output_muted;
545 static int cs4231_get_formats(struct sparcaudio_driver *drv)
547 return (AFMT_MU_LAW | AFMT_A_LAW |
548 AFMT_U8 | AFMT_IMA_ADPCM |
549 AFMT_S16_LE | AFMT_S16_BE);
552 static int cs4231_get_output_ports(struct sparcaudio_driver *drv)
554 return (AUDIO_LINE_OUT | AUDIO_SPEAKER | AUDIO_HEADPHONE);
557 static int cs4231_get_input_ports(struct sparcaudio_driver *drv)
559 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
561 /* This apparently applies only to APC ultras, not ebus ultras */
562 if (cs4231_chip->status & CS_STATUS_IS_ULTRA)
563 return (AUDIO_LINE_IN | AUDIO_MICROPHONE | AUDIO_ANALOG_LOOPBACK);
565 return (AUDIO_INTERNAL_CD_IN | AUDIO_LINE_IN |
566 AUDIO_MICROPHONE | AUDIO_ANALOG_LOOPBACK);
569 /* Set chip "output" port */
570 static int cs4231_set_output_port(struct sparcaudio_driver *drv, int value)
572 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
575 tprintk(("output port: %d\n", value));
576 /* Aaaaaah! It's all coming so fast! Turn it all off, then selectively
580 WRITE_IDR(READ_IDR() | MONO_IOCR_MUTE);
582 WRITE_IDR(READ_IDR() | PINCR_LINE_MUTE);
583 WRITE_IDR(READ_IDR() | PINCR_HDPH_MUTE);
585 if (value & AUDIO_SPEAKER) {
587 WRITE_IDR(READ_IDR() & ~MONO_IOCR_MUTE);
588 retval |= AUDIO_SPEAKER;
591 if (value & AUDIO_HEADPHONE) {
593 WRITE_IDR(READ_IDR() & ~PINCR_HDPH_MUTE);
594 retval |= AUDIO_HEADPHONE;
597 if (value & AUDIO_LINE_OUT) {
599 WRITE_IDR(READ_IDR() & ~PINCR_LINE_MUTE);
600 retval |= AUDIO_LINE_OUT;
603 cs4231_chip->perchip_info.play.port = retval;
608 static int cs4231_get_output_port(struct sparcaudio_driver *drv)
610 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
611 return cs4231_chip->perchip_info.play.port;
614 /* Set chip "input" port */
615 static int cs4231_set_input_port(struct sparcaudio_driver *drv, int value)
617 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
620 tprintk(("input port: %d\n", value));
622 /* You can have one and only one. This is probably wrong, but
623 * appears to be how SunOS is doing it. Should be able to mix.
624 * More work to be done. CD input mixable, analog loopback may be.
627 /* Ultra systems do not support AUDIO_INTERNAL_CD_IN */
628 /* This apparently applies only to APC ultras, not ebus ultras */
629 if (!(cs4231_chip->status & CS_STATUS_IS_ULTRA)) {
630 if (value & AUDIO_INTERNAL_CD_IN) {
632 WRITE_IDR(CDROM_ENABLE(READ_IDR()));
634 WRITE_IDR(CDROM_ENABLE(READ_IDR()));
635 retval = AUDIO_INTERNAL_CD_IN;
638 if ((value & AUDIO_LINE_IN)) {
640 WRITE_IDR(LINE_ENABLE(READ_IDR()));
642 WRITE_IDR(LINE_ENABLE(READ_IDR()));
643 retval = AUDIO_LINE_IN;
644 } else if (value & AUDIO_MICROPHONE) {
646 WRITE_IDR(MIC_ENABLE(READ_IDR()));
648 WRITE_IDR(MIC_ENABLE(READ_IDR()));
649 retval = AUDIO_MICROPHONE;
650 } else if (value & AUDIO_ANALOG_LOOPBACK) {
652 WRITE_IDR(OUTPUTLOOP_ENABLE(READ_IDR()));
654 WRITE_IDR(OUTPUTLOOP_ENABLE(READ_IDR()));
655 retval = AUDIO_ANALOG_LOOPBACK;
658 cs4231_chip->perchip_info.record.port = retval;
663 static int cs4231_get_input_port(struct sparcaudio_driver *drv)
665 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
666 return cs4231_chip->perchip_info.record.port;
669 /* Set chip "monitor" gain */
670 static int cs4231_set_monitor_volume(struct sparcaudio_driver *drv, int value)
672 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
675 tprintk(("monitor gain: %d\n", value));
677 /* This interpolation really sucks. The question is, be compatible
678 * with ScumOS/Sloaris or not?
680 a = CS4231_MON_MAX_ATEN - (value * (CS4231_MON_MAX_ATEN + 1) /
681 (AUDIO_MAX_GAIN + 1));
684 if (a >= CS4231_MON_MAX_ATEN)
685 WRITE_IDR(LOOPB_OFF);
687 WRITE_IDR((a << 2) | LOOPB_ON);
689 if (value == AUDIO_MAX_GAIN)
690 cs4231_chip->perchip_info.monitor_gain = AUDIO_MAX_GAIN;
692 cs4231_chip->perchip_info.monitor_gain =
693 ((CS4231_MAX_DEV_ATEN - a) *
694 (AUDIO_MAX_GAIN + 1) /
695 (CS4231_MAX_DEV_ATEN + 1));
700 static int cs4231_get_monitor_volume(struct sparcaudio_driver *drv)
702 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
704 return (int) cs4231_chip->perchip_info.monitor_gain;
707 static int cs4231_get_output_error(struct sparcaudio_driver *drv)
709 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
711 return (int) cs4231_chip->perchip_info.play.error;
714 static int cs4231_get_input_error(struct sparcaudio_driver *drv)
716 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
718 return (int) cs4231_chip->perchip_info.record.error;
721 #ifdef EB4231_SUPPORT
722 static int eb4231_get_output_samples(struct sparcaudio_driver *drv)
724 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
725 u32 dbcr = readl(cs4231_chip->eb2p + EBDMA_COUNT);
727 cs4231_length_to_samplecount(&cs4231_chip->perchip_info.play, dbcr);
729 return (cs4231_chip->perchip_info.play.samples -
730 ((count > cs4231_chip->perchip_info.play.samples)
734 static int eb4231_get_input_samples(struct sparcaudio_driver *drv)
736 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
737 u32 dbcr = readl(cs4231_chip->eb2c + EBDMA_COUNT);
739 cs4231_length_to_samplecount(&cs4231_chip->perchip_info.record, dbcr);
741 return (cs4231_chip->perchip_info.record.samples -
742 ((count > cs4231_chip->perchip_info.record.samples) ?
747 static int cs4231_get_output_samples(struct sparcaudio_driver *drv)
749 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
750 u32 dmapc = sbus_readl(cs4231_chip->regs + APCPC);
752 cs4231_length_to_samplecount(&cs4231_chip->perchip_info.play, dmapc);
754 return (cs4231_chip->perchip_info.play.samples -
755 ((count > cs4231_chip->perchip_info.play.samples)
759 static int cs4231_get_input_samples(struct sparcaudio_driver *drv)
761 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
762 u32 dmacc = sbus_readl(cs4231_chip->regs + APCCC);
764 cs4231_length_to_samplecount(&cs4231_chip->perchip_info.record, dmacc);
766 return (cs4231_chip->perchip_info.record.samples -
767 ((count > cs4231_chip->perchip_info.record.samples) ?
771 static int cs4231_get_output_pause(struct sparcaudio_driver *drv)
773 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
775 return (int) cs4231_chip->perchip_info.play.pause;
778 static int cs4231_get_input_pause(struct sparcaudio_driver *drv)
780 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
782 return (int) cs4231_chip->perchip_info.record.pause;
785 /* But for play/record we have these cheesy jacket routines because of
786 * how this crap gets set.
788 static int cs4231_set_input_volume(struct sparcaudio_driver *drv, int value)
790 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
792 cs4231_record_gain(drv, value,
793 cs4231_chip->perchip_info.record.balance);
798 static int cs4231_get_input_volume(struct sparcaudio_driver *drv)
800 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
802 return (int) cs4231_chip->perchip_info.record.gain;
805 static int cs4231_set_output_volume(struct sparcaudio_driver *drv, int value)
807 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
809 cs4231_play_gain(drv, value, cs4231_chip->perchip_info.play.balance);
814 static int cs4231_get_output_volume(struct sparcaudio_driver *drv)
816 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
818 return cs4231_chip->perchip_info.play.gain;
821 /* Likewise for balance */
822 static int cs4231_set_input_balance(struct sparcaudio_driver *drv, int value)
824 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
826 cs4231_chip->perchip_info.record.balance = value;
827 cs4231_record_gain(drv, cs4231_chip->perchip_info.record.gain,
828 cs4231_chip->perchip_info.record.balance);
833 static int cs4231_get_input_balance(struct sparcaudio_driver *drv)
835 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
837 return (int) cs4231_chip->perchip_info.record.balance;
840 static int cs4231_set_output_balance(struct sparcaudio_driver *drv, int value)
842 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
844 cs4231_chip->perchip_info.play.balance = value;
845 cs4231_play_gain(drv, cs4231_chip->perchip_info.play.gain,
846 cs4231_chip->perchip_info.play.balance);
851 static int cs4231_get_output_balance(struct sparcaudio_driver *drv)
853 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
855 return (int) cs4231_chip->perchip_info.play.balance;
858 /* Set chip record gain */
859 static int cs4231_record_gain(struct sparcaudio_driver *drv, int value,
860 unsigned char balance)
862 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
863 int tmp = 0, r, l, r_adj, l_adj;
864 unsigned char old_gain;
868 if (balance < AUDIO_MID_BALANCE) {
870 ((AUDIO_MID_BALANCE - balance) << AUDIO_BALANCE_SHIFT));
874 } else if (balance > AUDIO_MID_BALANCE) {
876 ((balance - AUDIO_MID_BALANCE) << AUDIO_BALANCE_SHIFT));
882 l_adj = l * (CS4231_MAX_GAIN + 1) / (AUDIO_MAX_GAIN + 1);
883 r_adj = r * (CS4231_MAX_GAIN + 1) / (AUDIO_MAX_GAIN + 1);
886 old_gain = READ_IDR();
887 WRITE_IDR(RECGAIN_SET(old_gain, l_adj));
889 old_gain = READ_IDR();
890 WRITE_IDR(RECGAIN_SET(old_gain, r_adj));
893 (l == 0) ? (tmp = 0) : (tmp = ((l_adj + 1) * AUDIO_MAX_GAIN) /
894 (CS4231_MAX_GAIN + 1));
895 } else if (r == value) {
896 (r == 0) ? (tmp = 0) : (tmp = ((r_adj + 1) * AUDIO_MAX_GAIN) /
897 (CS4231_MAX_GAIN + 1));
899 cs4231_chip->perchip_info.record.gain = tmp;
903 /* Set chip play gain */
904 static int cs4231_play_gain(struct sparcaudio_driver *drv, int value,
905 unsigned char balance)
907 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
908 int tmp = 0, r, l, r_adj, l_adj;
909 unsigned char old_gain;
911 tprintk(("in play_gain: %d %c\n", value, balance));
913 if (balance < AUDIO_MID_BALANCE) {
915 ((AUDIO_MID_BALANCE - balance) << AUDIO_BALANCE_SHIFT));
919 } else if (balance > AUDIO_MID_BALANCE) {
921 ((balance - AUDIO_MID_BALANCE) << AUDIO_BALANCE_SHIFT));
927 (l == 0) ? (l_adj = CS4231_MAX_DEV_ATEN) : (l_adj = CS4231_MAX_ATEN -
928 (l * (CS4231_MAX_ATEN + 1) /
929 (AUDIO_MAX_GAIN + 1)));
930 (r == 0) ? (r_adj = CS4231_MAX_DEV_ATEN) : (r_adj = CS4231_MAX_ATEN -
931 (r * (CS4231_MAX_ATEN + 1) /
932 (AUDIO_MAX_GAIN + 1)));
935 old_gain = READ_IDR();
936 WRITE_IDR(GAIN_SET(old_gain, l_adj));
938 old_gain = READ_IDR();
939 WRITE_IDR(GAIN_SET(old_gain, r_adj));
941 if ((value == 0) || (value == AUDIO_MAX_GAIN)) {
945 tmp = ((CS4231_MAX_ATEN - l_adj) * (AUDIO_MAX_GAIN + 1) /
946 (CS4231_MAX_ATEN + 1));
947 } else if (value == r) {
948 tmp = ((CS4231_MAX_ATEN - r_adj) * (AUDIO_MAX_GAIN + 1) /
949 (CS4231_MAX_ATEN + 1));
952 cs4231_chip->perchip_info.play.gain = tmp;
957 /* Reset the audio chip to a sane state. */
958 static void cs4231_chip_reset(struct sparcaudio_driver *drv)
960 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
963 tprintk(("in cs4231_chip_reset\n"));
965 if (cs4231_chip->status & CS_STATUS_IS_EBUS) {
966 #ifdef EB4231_SUPPORT
967 writel(EBUS_DCSR_RESET, cs4231_chip->eb2p + EBDMA_CSR);
968 writel(EBUS_DCSR_RESET, cs4231_chip->eb2c + EBDMA_CSR);
969 writel(EBUS_DCSR_BURST_SZ_16, cs4231_chip->eb2p + EBDMA_CSR);
970 writel(EBUS_DCSR_BURST_SZ_16, cs4231_chip->eb2c + EBDMA_CSR);
975 sbus_writel(APC_CHIP_RESET, cs4231_chip->regs + APCCSR);
976 sbus_writel(0x00, cs4231_chip->regs + APCCSR);
977 tmp = sbus_readl(cs4231_chip->regs + APCCSR);
978 tmp |= APC_CDC_RESET;
979 sbus_writel(tmp, cs4231_chip->regs + APCCSR);
983 tmp = sbus_readl(cs4231_chip->regs + APCCSR);
984 tmp &= ~(APC_CDC_RESET);
985 sbus_writel(tmp, cs4231_chip->regs + APCCSR);
988 WRITE_IAR(READ_IAR() | IAR_AUTOCAL_BEGIN);
991 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x0c);
992 WRITE_IDR(MISC_IR_MODE2);
994 /* This is the equivalent of DEFAULT_DATA_FMAT */
995 cs4231_set_input_encoding(drv, AUDIO_ENCODING_ULAW);
996 cs4231_set_input_rate(drv, CS4231_RATE);
997 cs4231_set_input_channels(drv, CS4231_CHANNELS);
998 cs4231_set_input_precision(drv, CS4231_PRECISION);
1000 cs4231_set_output_encoding(drv, AUDIO_ENCODING_ULAW);
1001 cs4231_set_output_rate(drv, CS4231_RATE);
1002 cs4231_set_output_channels(drv, CS4231_CHANNELS);
1003 cs4231_set_output_precision(drv, CS4231_PRECISION);
1007 /* see what we can turn on */
1009 if (vers & CS4231A) {
1010 tprintk(("This is a CS4231A\n"));
1011 cs4231_chip->status |= CS_STATUS_REV_A;
1013 cs4231_chip->status &= ~CS_STATUS_REV_A;
1016 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x10);
1017 WRITE_IDR(OLB_ENABLE);
1019 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x11);
1020 if (cs4231_chip->status & CS_STATUS_REV_A)
1021 WRITE_IDR(HPF_ON | XTALE_ON);
1025 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x1a);
1028 /* Now set things up for defaults */
1029 cs4231_set_input_balance(drv, AUDIO_MID_BALANCE);
1030 cs4231_set_output_balance(drv, AUDIO_MID_BALANCE);
1032 cs4231_set_input_volume(drv, CS4231_DEFAULT_RECGAIN);
1033 cs4231_set_output_volume(drv, CS4231_DEFAULT_PLAYGAIN);
1035 cs4231_set_input_port(drv, AUDIO_MICROPHONE);
1036 cs4231_set_output_port(drv, AUDIO_SPEAKER);
1038 cs4231_set_monitor_volume(drv, LOOPB_OFF);
1040 WRITE_IAR(IAR_AUTOCAL_END);
1044 WRITE_IAR(IAR_AUTOCAL_BEGIN | 0x09);
1045 WRITE_IDR(READ_IDR() & ACAL_DISABLE);
1046 WRITE_IAR(IAR_AUTOCAL_END);
1050 cs4231_output_muted(drv, 0);
1052 cs4231_chip->recording_count = 0;
1053 cs4231_chip->input_next_dma_handle = 0;
1054 cs4231_chip->input_dma_handle = 0;
1055 cs4231_chip->input_next_dma_size = 0;
1056 cs4231_chip->input_dma_size = 0;
1058 cs4231_chip->playing_count = 0;
1059 cs4231_chip->output_next_dma_handle = 0;
1060 cs4231_chip->output_dma_handle = 0;
1061 cs4231_chip->output_next_dma_size = 0;
1062 cs4231_chip->output_dma_size = 0;
1066 cs4231_length_to_samplecount(struct audio_prinfo *thisdir, unsigned int length)
1070 if (thisdir->channels == 2)
1071 count = (length / 2);
1075 if (thisdir->encoding == AUDIO_ENCODING_LINEAR)
1076 count = (count / 2);
1077 else if (thisdir->encoding == AUDIO_ENCODING_DVI)
1078 count = (count / 4);
1083 #ifdef EB4231_SUPPORT
1084 static void eb4231_getsamplecount(struct sparcaudio_driver *drv,
1085 unsigned int length,
1086 unsigned int direction)
1088 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1089 struct audio_prinfo *thisdir;
1090 unsigned int count, curcount, nextcount, dbcr;
1092 if(direction == 1) {
1093 thisdir = &cs4231_chip->perchip_info.record;
1094 dbcr = readl(cs4231_chip->eb2c + EBDMA_COUNT);
1095 nextcount = cs4231_chip->input_next_dma_size;
1097 thisdir = &cs4231_chip->perchip_info.play;
1098 dbcr = readl(cs4231_chip->eb2p + EBDMA_COUNT);
1099 nextcount = cs4231_chip->output_next_dma_size;
1101 curcount = cs4231_length_to_samplecount(thisdir, dbcr);
1102 count = thisdir->samples;
1103 length = cs4231_length_to_samplecount(thisdir, length);
1104 /* normalize for where we are. */
1105 thisdir->samples = ((count - nextcount) + (length - curcount));
1109 static void cs4231_getsamplecount(struct sparcaudio_driver *drv,
1110 unsigned int length,
1111 unsigned int direction)
1113 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1114 struct audio_prinfo *thisdir;
1115 unsigned int count, nextcount, curcount;
1118 if (direction == 1) {
1120 thisdir = &cs4231_chip->perchip_info.record;
1121 tmp = sbus_readl(cs4231_chip->regs + APCCC);
1122 curcount = cs4231_length_to_samplecount(thisdir, tmp);
1123 tmp = sbus_readl(cs4231_chip->regs + APCCNC);
1124 nextcount = cs4231_length_to_samplecount(thisdir, tmp);
1127 thisdir = &cs4231_chip->perchip_info.play;
1128 tmp = sbus_readl(cs4231_chip->regs + APCPC);
1129 curcount = cs4231_length_to_samplecount(thisdir, tmp);
1130 tmp = sbus_readl(cs4231_chip->regs + APCPNC);
1131 nextcount = cs4231_length_to_samplecount(thisdir, tmp);
1133 count = thisdir->samples;
1134 length = cs4231_length_to_samplecount(thisdir, length);
1136 /* normalize for where we are. */
1137 thisdir->samples = ((count - nextcount) + (length - curcount));
1140 static int cs4231_open(struct inode * inode, struct file * file, struct sparcaudio_driver *drv)
1142 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1144 /* Set the default audio parameters if not already in use. */
1145 if (file->f_mode & FMODE_WRITE) {
1146 if (!(drv->flags & SDF_OPEN_WRITE) &&
1147 (cs4231_chip->perchip_info.play.active == 0)) {
1148 cs4231_chip->perchip_info.play.open = 1;
1149 cs4231_chip->perchip_info.play.samples =
1150 cs4231_chip->perchip_info.play.error = 0;
1154 if (file->f_mode & FMODE_READ) {
1155 if (!(drv->flags & SDF_OPEN_READ) &&
1156 (cs4231_chip->perchip_info.record.active == 0)) {
1157 cs4231_chip->perchip_info.record.open = 1;
1158 cs4231_chip->perchip_info.record.samples =
1159 cs4231_chip->perchip_info.record.error = 0;
1171 static void cs4231_release(struct inode * inode, struct file * file, struct sparcaudio_driver *drv)
1173 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *)drv->private;
1174 void (*dma_unmap_single)(struct sbus_dev *, dma_addr_t, size_t, int) = sbus_unmap_single;
1176 #ifdef EB4231_SUPPORT
1177 if (cs4231_chip->status & CS_STATUS_IS_EBUS)
1178 dma_unmap_single = (void (*)(struct sbus_dev *, dma_addr_t, size_t, int)) pci_unmap_single;
1180 /* zero out any info about what data we have as well */
1181 if (file->f_mode & FMODE_READ) {
1182 /* stop capture here or midlevel? */
1183 cs4231_chip->perchip_info.record.open = 0;
1184 if (cs4231_chip->input_dma_handle) {
1185 dma_unmap_single(drv->dev,
1186 cs4231_chip->input_dma_handle,
1187 cs4231_chip->input_dma_size,
1188 SBUS_DMA_FROMDEVICE);
1189 cs4231_chip->input_dma_handle = 0;
1190 cs4231_chip->input_dma_size = 0;
1192 if (cs4231_chip->input_next_dma_handle) {
1193 dma_unmap_single(drv->dev,
1194 cs4231_chip->input_next_dma_handle,
1195 cs4231_chip->input_next_dma_size,
1196 SBUS_DMA_FROMDEVICE);
1197 cs4231_chip->input_next_dma_handle = 0;
1198 cs4231_chip->input_next_dma_size = 0;
1202 if (file->f_mode & FMODE_WRITE) {
1203 cs4231_chip->perchip_info.play.active =
1204 cs4231_chip->perchip_info.play.open = 0;
1205 if (cs4231_chip->output_dma_handle) {
1206 dma_unmap_single(drv->dev,
1207 cs4231_chip->output_dma_handle,
1208 cs4231_chip->output_dma_size,
1210 cs4231_chip->output_dma_handle = 0;
1211 cs4231_chip->output_dma_size = 0;
1213 if (cs4231_chip->output_next_dma_handle) {
1214 dma_unmap_single(drv->dev,
1215 cs4231_chip->output_next_dma_handle,
1216 cs4231_chip->output_next_dma_size,
1218 cs4231_chip->output_next_dma_handle = 0;
1219 cs4231_chip->output_next_dma_size = 0;
1223 if (!cs4231_chip->perchip_info.play.open &&
1224 !cs4231_chip->perchip_info.record.open &&
1225 (cs4231_chip->status & CS_STATUS_INIT_ON_CLOSE)) {
1226 cs4231_chip_reset(drv);
1227 cs4231_chip->status &= ~CS_STATUS_INIT_ON_CLOSE;
1233 static void cs4231_playintr(struct sparcaudio_driver *drv, int push)
1235 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1239 if (!cs4231_chip->perchip_info.play.active) {
1240 sbus_writel(cs4231_chip->output_next_dma_handle,
1241 cs4231_chip->regs + APCPNVA);
1242 sbus_writel(cs4231_chip->output_next_dma_size,
1243 cs4231_chip->regs + APCPNC);
1245 sparcaudio_output_done(drv, 0);
1249 if (cs4231_chip->playlen == 0 && cs4231_chip->output_size > 0)
1250 cs4231_chip->playlen = cs4231_chip->output_size;
1252 if (cs4231_chip->output_dma_handle) {
1253 sbus_unmap_single(drv->dev,
1254 cs4231_chip->output_dma_handle,
1255 cs4231_chip->output_dma_size,
1257 cs4231_chip->output_dma_handle = 0;
1258 cs4231_chip->output_dma_size = 0;
1259 cs4231_chip->playing_count--;
1263 if (cs4231_chip->output_next_dma_handle) {
1264 cs4231_chip->output_dma_handle = cs4231_chip->output_next_dma_handle;
1265 cs4231_chip->output_dma_size = cs4231_chip->output_next_dma_size;
1266 cs4231_chip->output_next_dma_size = 0;
1267 cs4231_chip->output_next_dma_handle = 0;
1270 if ((cs4231_chip->output_ptr && cs4231_chip->output_size > 0) &&
1271 !(cs4231_chip->perchip_info.play.pause)) {
1272 cs4231_chip->output_next_dma_handle =
1273 sbus_map_single(drv->dev,
1274 (char *)cs4231_chip->output_ptr,
1275 cs4231_chip->output_size,
1277 cs4231_chip->output_next_dma_size = cs4231_chip->output_size;
1278 sbus_writel(cs4231_chip->output_next_dma_handle,
1279 cs4231_chip->regs + APCPNVA);
1280 sbus_writel(cs4231_chip->output_next_dma_size,
1281 cs4231_chip->regs + APCPNC);
1282 cs4231_chip->output_size = 0;
1283 cs4231_chip->output_ptr = NULL;
1284 cs4231_chip->playing_count++;
1287 sbus_writel(0, cs4231_chip->regs + APCPNVA);
1288 sbus_writel(0, cs4231_chip->regs + APCPNC);
1291 sparcaudio_output_done(drv, status);
1294 #ifdef EB4231_SUPPORT
1295 static void eb4231_playintr(struct sparcaudio_driver *drv)
1297 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1300 if (cs4231_chip->playlen == 0 && cs4231_chip->output_size > 0)
1301 cs4231_chip->playlen = cs4231_chip->output_size;
1303 if (cs4231_chip->output_dma_handle) {
1304 pci_unmap_single((struct pci_dev *)drv->dev,
1305 cs4231_chip->output_dma_handle,
1306 cs4231_chip->output_dma_size,
1308 cs4231_chip->output_dma_handle = 0;
1309 cs4231_chip->output_dma_size = 0;
1310 cs4231_chip->playing_count--;
1314 if(cs4231_chip->output_next_dma_handle) {
1315 cs4231_chip->output_dma_handle = cs4231_chip->output_next_dma_handle;
1316 cs4231_chip->output_dma_size = cs4231_chip->output_next_dma_size;
1317 cs4231_chip->output_next_dma_handle = 0;
1318 cs4231_chip->output_next_dma_size = 0;
1321 if ((cs4231_chip->output_ptr && cs4231_chip->output_size > 0) &&
1322 !(cs4231_chip->perchip_info.play.pause)) {
1323 cs4231_chip->output_next_dma_handle =
1324 pci_map_single((struct pci_dev *)drv->dev,
1325 (char *)cs4231_chip->output_ptr,
1326 cs4231_chip->output_size,
1328 cs4231_chip->output_next_dma_size = cs4231_chip->output_size;
1330 writel(cs4231_chip->output_next_dma_size,
1331 cs4231_chip->eb2p + EBDMA_COUNT);
1332 writel(cs4231_chip->output_next_dma_handle,
1333 cs4231_chip->eb2p + EBDMA_ADDR);
1334 cs4231_chip->output_size = 0;
1335 cs4231_chip->output_ptr = NULL;
1336 cs4231_chip->playing_count++;
1340 sparcaudio_output_done(drv, status);
1344 static void cs4231_recclear(int fmt, char *dmabuf, int length)
1347 case AUDIO_ENCODING_LINEAR:
1348 memset(dmabuf, 0x00, length);
1350 case AUDIO_ENCODING_ALAW:
1351 memset(dmabuf, 0xd5, length);
1353 case AUDIO_ENCODING_ULAW:
1354 memset(dmabuf, 0xff, length);
1359 static int cs4231_recintr(struct sparcaudio_driver *drv)
1361 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1364 if (cs4231_chip->perchip_info.record.active == 0) {
1365 dprintk(("going inactive\n"));
1366 cs4231_pollinput(drv);
1367 cs4231_disable_rec(drv);
1370 if (cs4231_chip->input_dma_handle) {
1371 sbus_unmap_single(drv->dev,
1372 cs4231_chip->input_dma_handle,
1373 cs4231_chip->input_dma_size,
1374 SBUS_DMA_FROMDEVICE);
1375 cs4231_chip->input_dma_handle = 0;
1376 cs4231_chip->input_dma_size = 0;
1377 cs4231_chip->recording_count--;
1381 if (cs4231_chip->input_next_dma_handle) {
1382 cs4231_chip->input_dma_handle = cs4231_chip->input_next_dma_handle;
1383 cs4231_chip->input_dma_size = cs4231_chip->input_next_dma_size;
1384 cs4231_chip->input_next_dma_size = 0;
1385 cs4231_chip->input_next_dma_handle = 0;
1388 if ((cs4231_chip->input_ptr && cs4231_chip->input_size > 0) &&
1389 !(cs4231_chip->perchip_info.record.pause)) {
1390 cs4231_recclear(cs4231_chip->perchip_info.record.encoding,
1391 (char *)cs4231_chip->input_ptr,
1392 cs4231_chip->input_size);
1393 cs4231_chip->input_next_dma_handle =
1394 sbus_map_single(drv->dev,
1395 (char *)cs4231_chip->input_ptr,
1396 cs4231_chip->input_size,
1397 SBUS_DMA_FROMDEVICE);
1398 cs4231_chip->input_next_dma_size = cs4231_chip->input_size;
1399 sbus_writel(cs4231_chip->input_next_dma_handle,
1400 cs4231_chip->regs + APCCNVA);
1401 sbus_writel(cs4231_chip->input_next_dma_size,
1402 cs4231_chip->regs + APCCNC);
1403 cs4231_chip->input_size = 0;
1404 cs4231_chip->input_ptr = NULL;
1405 cs4231_chip->recording_count++;
1408 sbus_writel(0, cs4231_chip->regs + APCCNVA);
1409 sbus_writel(0, cs4231_chip->regs + APCCNC);
1412 sparcaudio_input_done(drv, status);
1416 #ifdef EB4231_SUPPORT
1417 static int eb4231_recintr(struct sparcaudio_driver *drv)
1419 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1422 if (cs4231_chip->perchip_info.record.active == 0) {
1423 dprintk(("going inactive\n"));
1424 eb4231_pollinput(drv);
1425 cs4231_disable_rec(drv);
1428 if (cs4231_chip->input_dma_handle) {
1429 pci_unmap_single((struct pci_dev *)drv->dev,
1430 cs4231_chip->input_dma_handle,
1431 cs4231_chip->input_dma_size,
1432 PCI_DMA_FROMDEVICE);
1433 cs4231_chip->input_dma_handle = 0;
1434 cs4231_chip->input_dma_size = 0;
1435 cs4231_chip->recording_count--;
1439 if (cs4231_chip->input_next_dma_handle) {
1440 cs4231_chip->input_dma_handle = cs4231_chip->input_next_dma_handle;
1441 cs4231_chip->input_dma_size = cs4231_chip->input_next_dma_size;
1442 cs4231_chip->input_next_dma_size = 0;
1443 cs4231_chip->input_next_dma_handle = 0;
1446 if ((cs4231_chip->input_ptr && cs4231_chip->input_size > 0) &&
1447 !(cs4231_chip->perchip_info.record.pause)) {
1448 cs4231_recclear(cs4231_chip->perchip_info.record.encoding,
1449 (char *)cs4231_chip->input_ptr,
1450 cs4231_chip->input_size);
1452 cs4231_chip->input_next_dma_handle =
1453 pci_map_single((struct pci_dev *)drv->dev,
1454 (char *)cs4231_chip->input_ptr,
1455 cs4231_chip->input_size,
1456 PCI_DMA_FROMDEVICE);
1457 cs4231_chip->input_next_dma_size = cs4231_chip->input_size;
1459 writel(cs4231_chip->input_next_dma_size,
1460 cs4231_chip->eb2c + EBDMA_COUNT);
1461 writel(cs4231_chip->input_next_dma_handle,
1462 cs4231_chip->eb2c + EBDMA_ADDR);
1464 cs4231_chip->input_size = 0;
1465 cs4231_chip->input_ptr = NULL;
1466 cs4231_chip->recording_count++;
1470 sparcaudio_input_done(drv, status);
1475 #ifdef EB4231_SUPPORT
1476 static void eb4231_start_output(struct sparcaudio_driver *drv, __u8 * buffer,
1477 unsigned long count)
1479 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1482 cs4231_chip->output_ptr = buffer;
1483 cs4231_chip->output_size = count;
1485 if (cs4231_chip->perchip_info.play.active ||
1486 (cs4231_chip->perchip_info.play.pause))
1491 cs4231_chip->perchip_info.play.active = 1;
1492 cs4231_chip->playing_count = 0;
1494 dcsr = readl(cs4231_chip->eb2p + EBDMA_CSR);
1495 if (!(dcsr & EBUS_DCSR_EN_DMA)) {
1496 writel(EBUS_DCSR_RESET, cs4231_chip->eb2p + EBDMA_CSR);
1497 writel(EBUS_DCSR_BURST_SZ_16, cs4231_chip->eb2p + EBDMA_CSR);
1499 eb4231_playintr(drv);
1501 writel(EBUS_DCSR_BURST_SZ_16 |
1502 (EBUS_DCSR_EN_DMA | EBUS_DCSR_INT_EN |
1503 EBUS_DCSR_EN_CNT | EBUS_DCSR_EN_NEXT),
1504 cs4231_chip->eb2p + EBDMA_CSR);
1506 cs4231_enable_play(drv);
1510 eb4231_playintr(drv);
1515 static void cs4231_start_output(struct sparcaudio_driver *drv, __u8 * buffer,
1516 unsigned long count)
1518 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1521 tprintk(("in 4231 start output\n"));
1522 cs4231_chip->output_ptr = buffer;
1523 cs4231_chip->output_size = count;
1525 if (cs4231_chip->perchip_info.play.active ||
1526 (cs4231_chip->perchip_info.play.pause))
1531 cs4231_chip->perchip_info.play.active = 1;
1532 cs4231_chip->playing_count = 0;
1534 csr = sbus_readl(cs4231_chip->regs + APCCSR);
1535 if ((csr & APC_PPAUSE) || !(csr & APC_PDMA_READY)) {
1538 csr &= ~APC_XINT_PLAY;
1539 sbus_writel(csr, cs4231_chip->regs + APCCSR);
1541 sbus_writel(csr, cs4231_chip->regs + APCCSR);
1543 pnva = sbus_readl(cs4231_chip->regs + APCPNVA);
1544 cs4231_playintr(drv, (pnva == 0) ? 1 : 0);
1546 csr |= APC_PLAY_SETUP;
1547 sbus_writel(csr, cs4231_chip->regs + APCCSR);
1548 cs4231_enable_play(drv);
1554 #ifdef EB4231_SUPPORT
1555 static void eb4231_stop_output(struct sparcaudio_driver *drv)
1557 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1560 dprintk(("eb4231_stop_output: dcsr 0x%x dacr 0x%x dbcr %d\n",
1561 readl(cs4231_chip->eb2p + EBDMA_CSR),
1562 readl(cs4231_chip->eb2p + EBDMA_ADDR),
1563 readl(cs4231_chip->eb2p + EBDMA_COUNT)));
1565 cs4231_chip->output_ptr = NULL;
1566 cs4231_chip->output_size = 0;
1568 if (cs4231_chip->output_dma_handle) {
1569 pci_unmap_single((struct pci_dev *)drv->dev,
1570 cs4231_chip->output_dma_handle,
1571 cs4231_chip->output_dma_size,
1573 cs4231_chip->output_dma_handle = 0;
1574 cs4231_chip->output_dma_size = 0;
1577 if (cs4231_chip->output_next_dma_handle) {
1578 pci_unmap_single((struct pci_dev *)drv->dev,
1579 cs4231_chip->output_next_dma_handle,
1580 cs4231_chip->output_next_dma_size,
1582 cs4231_chip->output_next_dma_handle = 0;
1583 cs4231_chip->output_next_dma_size = 0;
1585 dcsr = readl(cs4231_chip->eb2p + EBDMA_CSR);
1586 if(dcsr & EBUS_DCSR_EN_DMA)
1587 writel(dcsr & ~EBUS_DCSR_EN_DMA,
1588 cs4231_chip->eb2p + EBDMA_CSR);
1590 /* Else subsequent speed setting changes are ignored by the chip. */
1591 cs4231_disable_play(drv);
1595 static void cs4231_stop_output(struct sparcaudio_driver *drv)
1597 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1599 tprintk(("in cs4231_stop_output\n"));
1600 cs4231_chip->output_ptr = NULL;
1601 cs4231_chip->output_size = 0;
1603 if (cs4231_chip->output_dma_handle) {
1604 sbus_unmap_single(drv->dev,
1605 cs4231_chip->output_dma_handle,
1606 cs4231_chip->output_dma_size,
1608 cs4231_chip->output_dma_handle = 0;
1609 cs4231_chip->output_dma_size = 0;
1612 if (cs4231_chip->output_next_dma_handle) {
1613 sbus_unmap_single(drv->dev,
1614 cs4231_chip->output_next_dma_handle,
1615 cs4231_chip->output_next_dma_size,
1617 cs4231_chip->output_next_dma_handle = 0;
1618 cs4231_chip->output_next_dma_size = 0;
1620 #if 0 /* Not safe without shutting off the DMA controller as well. -DaveM */
1621 /* Else subsequent speed setting changes are ignored by the chip. */
1622 cs4231_disable_play(drv);
1626 #ifdef EB4231_SUPPORT
1627 static void eb4231_pollinput(struct sparcaudio_driver *drv)
1629 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1635 dcsr = readl(cs4231_chip->eb2c + EBDMA_CSR);
1636 if (dcsr & EBUS_DCSR_TC)
1639 } while (x <= CS_TIMEOUT);
1641 writel(dcsr | EBUS_DCSR_TC,
1642 cs4231_chip->eb2c + EBDMA_CSR);
1646 static void cs4231_pollinput(struct sparcaudio_driver *drv)
1648 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1654 csr = sbus_readl(cs4231_chip->regs + APCCSR);
1655 if (csr & APC_XINT_COVF)
1658 } while (x <= CS_TIMEOUT);
1660 sbus_writel(csr | APC_XINT_CEMP,
1661 cs4231_chip->regs + APCCSR);
1664 static void cs4231_start_input(struct sparcaudio_driver *drv, __u8 * buffer,
1665 unsigned long count)
1667 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1670 cs4231_chip->input_ptr = buffer;
1671 cs4231_chip->input_size = count;
1673 if (cs4231_chip->perchip_info.record.active ||
1674 (cs4231_chip->perchip_info.record.pause))
1679 cs4231_chip->perchip_info.record.active = 1;
1680 cs4231_chip->recording_count = 0;
1682 csr = sbus_readl(cs4231_chip->regs + APCCSR);
1683 if ((csr & APC_CPAUSE) || !(csr & APC_CDMA_READY)) {
1684 csr &= ~APC_XINT_CAPT;
1685 sbus_writel(csr, cs4231_chip->regs + APCCSR);
1687 sbus_writel(csr, cs4231_chip->regs + APCCSR);
1689 cs4231_recintr(drv);
1691 csr |= APC_CAPT_SETUP;
1692 sbus_writel(csr, cs4231_chip->regs + APCCSR);
1694 cs4231_enable_rec(drv);
1697 cs4231_recintr(drv);
1701 static void cs4231_stop_input(struct sparcaudio_driver *drv)
1703 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1706 cs4231_chip->perchip_info.record.active = 0;
1708 csr = sbus_readl(cs4231_chip->regs + APCCSR);
1710 sbus_writel(csr, cs4231_chip->regs + APCCSR);
1712 cs4231_chip->input_ptr = NULL;
1713 cs4231_chip->input_size = 0;
1715 if (cs4231_chip->input_dma_handle) {
1716 sbus_unmap_single(drv->dev,
1717 cs4231_chip->input_dma_handle,
1718 cs4231_chip->input_dma_size,
1719 SBUS_DMA_FROMDEVICE);
1720 cs4231_chip->input_dma_handle = 0;
1721 cs4231_chip->input_dma_size = 0;
1724 if (cs4231_chip->input_next_dma_handle) {
1725 sbus_unmap_single(drv->dev,
1726 cs4231_chip->input_next_dma_handle,
1727 cs4231_chip->input_next_dma_size,
1728 SBUS_DMA_FROMDEVICE);
1729 cs4231_chip->input_next_dma_handle = 0;
1730 cs4231_chip->input_next_dma_size = 0;
1733 cs4231_pollinput(drv);
1736 #ifdef EB4231_SUPPORT
1737 static void eb4231_start_input(struct sparcaudio_driver *drv, __u8 * buffer,
1738 unsigned long count)
1740 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1743 cs4231_chip->input_ptr = buffer;
1744 cs4231_chip->input_size = count;
1746 if (cs4231_chip->perchip_info.record.active ||
1747 (cs4231_chip->perchip_info.record.pause))
1751 cs4231_chip->perchip_info.record.active = 1;
1752 cs4231_chip->recording_count = 0;
1754 dcsr = readl(cs4231_chip->eb2c + EBDMA_CSR);
1755 if (!(dcsr & EBUS_DCSR_EN_DMA)) {
1756 writel(EBUS_DCSR_RESET, cs4231_chip->eb2c + EBDMA_CSR);
1757 writel(EBUS_DCSR_BURST_SZ_16, cs4231_chip->eb2c + EBDMA_CSR);
1759 eb4231_recintr(drv);
1761 writel(EBUS_DCSR_BURST_SZ_16 |
1762 (EBUS_DCSR_EN_DMA | EBUS_DCSR_INT_EN |
1763 EBUS_DCSR_EN_CNT | EBUS_DCSR_EN_NEXT),
1764 cs4231_chip->eb2c + EBDMA_CSR);
1766 cs4231_enable_rec(drv);
1769 eb4231_recintr(drv);
1773 static void eb4231_stop_input(struct sparcaudio_driver *drv)
1775 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1778 cs4231_chip->perchip_info.record.active = 0;
1780 cs4231_chip->input_ptr = NULL;
1781 cs4231_chip->input_size = 0;
1783 if (cs4231_chip->input_dma_handle) {
1784 pci_unmap_single((struct pci_dev *)drv->dev,
1785 cs4231_chip->input_dma_handle,
1786 cs4231_chip->input_dma_size,
1787 PCI_DMA_FROMDEVICE);
1788 cs4231_chip->input_dma_handle = 0;
1789 cs4231_chip->input_dma_size = 0;
1792 if (cs4231_chip->input_next_dma_handle) {
1793 pci_unmap_single((struct pci_dev *)drv->dev,
1794 cs4231_chip->input_next_dma_handle,
1795 cs4231_chip->input_next_dma_size,
1796 PCI_DMA_FROMDEVICE);
1797 cs4231_chip->input_next_dma_handle = 0;
1798 cs4231_chip->input_next_dma_size = 0;
1801 dcsr = readl(cs4231_chip->eb2c + EBDMA_CSR);
1802 if (dcsr & EBUS_DCSR_EN_DMA)
1803 writel(dcsr & ~EBUS_DCSR_EN_DMA, cs4231_chip->eb2c + EBDMA_CSR);
1805 cs4231_disable_rec(drv);
1809 static int cs4231_set_output_pause(struct sparcaudio_driver *drv, int value)
1811 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1813 cs4231_chip->perchip_info.play.pause = value;
1816 sparcaudio_output_done(drv, 0);
1821 static int cs4231_set_output_error(struct sparcaudio_driver *drv, int value)
1823 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1826 i = cs4231_chip->perchip_info.play.error;
1827 cs4231_chip->perchip_info.play.error = value;
1832 static int cs4231_set_input_error(struct sparcaudio_driver *drv, int value)
1834 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1837 i = cs4231_chip->perchip_info.record.error;
1838 cs4231_chip->perchip_info.record.error = value;
1843 static int cs4231_set_output_samples(struct sparcaudio_driver *drv, int value)
1845 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *)drv->private;
1848 i = cs4231_chip->perchip_info.play.samples;
1849 cs4231_chip->perchip_info.play.samples = value;
1854 static int cs4231_set_input_samples(struct sparcaudio_driver *drv, int value)
1856 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1859 i = cs4231_chip->perchip_info.record.samples;
1860 cs4231_chip->perchip_info.record.samples = value;
1865 static int cs4231_set_input_pause(struct sparcaudio_driver *drv, int value)
1867 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1869 cs4231_chip->perchip_info.record.pause = value;
1872 cs4231_stop_input(drv);
1877 static void cs4231_audio_getdev(struct sparcaudio_driver *drv,
1878 audio_device_t * audinfo)
1880 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1882 strncpy(audinfo->name, "SUNW,CS4231", sizeof(audinfo->name) - 1);
1884 /* a: SPARCstation 4/5 b: Ultra 1/2 (electron) */
1885 /* c: Ultra 1/2 PCI? (positron) d: ppc */
1886 /* e: x86 f: Ultra Enterprise? (tazmo) */
1887 /* g: Ultra 30? (quark) h: Ultra 5/10? (darwin) */
1888 /* apparently Ultra 1, Ultra 2 don't have internal CD input */
1889 if (cs4231_chip->status & CS_STATUS_IS_ULTRA)
1890 strncpy(audinfo->version, "b", sizeof(audinfo->version) - 1);
1892 strncpy(audinfo->version, "a", sizeof(audinfo->version) - 1);
1893 strncpy(audinfo->config, "onboard1", sizeof(audinfo->config) - 1);
1897 static int cs4231_audio_getdev_sunos(struct sparcaudio_driver *drv)
1899 return AUDIO_DEV_CS4231;
1902 static void cs4231_loopback(struct sparcaudio_driver *drv, unsigned int value)
1904 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1907 WRITE_IDR(value ? LOOPB_ON : 0);
1910 static int cs4231_ioctl(struct inode * inode, struct file * file,
1911 unsigned int cmd, unsigned long arg,
1912 struct sparcaudio_driver *drv)
1914 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1918 case AUDIO_DIAG_LOOPBACK:
1919 cs4231_chip->status |= CS_STATUS_INIT_ON_CLOSE;
1920 cs4231_loopback(drv, (unsigned int)arg);
1929 #ifdef EB4231_SUPPORT
1930 /* ebus audio capture interrupt handler. */
1931 void eb4231_cinterrupt(int irq, void *dev_id, struct pt_regs *regs)
1933 struct sparcaudio_driver *drv = (struct sparcaudio_driver *) dev_id;
1934 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1937 /* Clear the interrupt. */
1938 dummy = readl(cs4231_chip->eb2c + EBDMA_CSR);
1939 writel(dummy, cs4231_chip->eb2c + EBDMA_CSR);
1941 if ((dummy & EBUS_DCSR_TC) != 0
1942 /*&& (dummy & EBUS_DCSR_A_LOADED) != 0*/) {
1943 cs4231_chip->perchip_info.record.samples +=
1944 cs4231_length_to_samplecount(&(cs4231_chip->perchip_info.record),
1945 cs4231_chip->reclen);
1946 eb4231_recintr(drv);
1949 if ((dummy & EBUS_DCSR_A_LOADED) == 0) {
1950 cs4231_chip->perchip_info.record.active = 0;
1951 eb4231_recintr(drv);
1952 eb4231_getsamplecount(drv, cs4231_chip->reclen, 1);
1956 /* ebus audio play interrupt handler. */
1957 void eb4231_pinterrupt(int irq, void *dev_id, struct pt_regs *regs)
1959 struct sparcaudio_driver *drv = (struct sparcaudio_driver *) dev_id;
1960 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1963 /* Clear the interrupt. Bleh, when not using the next-address
1964 * feature, TC can only be cleared by a reset.
1966 dummy = readl(cs4231_chip->eb2p + EBDMA_CSR);
1967 writel(dummy, cs4231_chip->eb2p + EBDMA_CSR);
1969 /* If we get a terminal count and address loaded condition,
1970 * this means the DNAR was copied into DACR.
1972 if((dummy & EBUS_DCSR_TC) != 0
1973 /*&& (dummy & EBUS_DCSR_A_LOADED) != 0*/) {
1974 cs4231_chip->perchip_info.play.samples +=
1975 cs4231_length_to_samplecount(&(cs4231_chip->perchip_info.play),
1976 cs4231_chip->playlen);
1977 eb4231_playintr(drv);
1980 if((dummy & EBUS_DCSR_A_LOADED) == 0) {
1981 cs4231_chip->perchip_info.play.active = 0;
1982 eb4231_playintr(drv);
1983 eb4231_getsamplecount(drv, cs4231_chip->playlen, 0);
1988 /* Audio interrupt handler. */
1989 void cs4231_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1991 struct sparcaudio_driver *drv = (struct sparcaudio_driver *) dev_id;
1992 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
1995 dprintk(("in cs4231_interrupt\n"));
1997 /* Clear the interrupt. */
1998 dummy = sbus_readl(cs4231_chip->regs + APCCSR);
1999 sbus_writel(dummy, cs4231_chip->regs + APCCSR);
2001 /* now go through and figure out what gets to claim the interrupt
2002 * if anything since we may be doing shared interrupts
2004 if (dummy & APC_PLAY_INT) {
2005 if (dummy & APC_XINT_PNVA) {
2006 cs4231_chip->perchip_info.play.samples +=
2007 cs4231_length_to_samplecount(&(cs4231_chip->perchip_info.play),
2008 cs4231_chip->playlen);
2009 if (!(dummy & APC_XINT_EMPT))
2010 cs4231_playintr(drv, 1);
2012 /* Any other conditions we need worry about? */
2015 if (dummy & APC_CAPT_INT) {
2016 if (dummy & APC_XINT_CNVA) {
2017 cs4231_chip->perchip_info.record.samples +=
2018 cs4231_length_to_samplecount(&(cs4231_chip->perchip_info.record),
2019 cs4231_chip->reclen);
2020 cs4231_recintr(drv);
2022 /* Any other conditions we need worry about? */
2026 if (dummy & APC_XINT_CEMP) {
2027 if (cs4231_chip->perchip_info.record.active == 0) {
2029 cs4231_chip->perchip_info.record.active = 0;
2030 cs4231_chip->perchip_info.record.error = 1;
2031 cs4231_recintr(drv);
2035 if (dummy & APC_XINT_EMPT) {
2036 if (!cs4231_chip->output_next_dma_handle) {
2037 u32 csr = sbus_readl(cs4231_chip->regs + APCCSR);
2040 sbus_writel(csr, cs4231_chip->regs + APCCSR);
2041 cs4231_disable_play(drv);
2042 cs4231_chip->perchip_info.play.error = 1;
2044 cs4231_chip->perchip_info.play.active = 0;
2045 cs4231_playintr(drv, 0);
2047 cs4231_getsamplecount(drv, cs4231_chip->playlen, 0);
2050 if (dummy & APC_GENL_INT) {
2051 /* If we get here we must be sharing an interrupt, but I haven't code
2052 * to handle this right now.
2057 static struct sparcaudio_operations cs4231_ops = {
2061 cs4231_start_output,
2065 cs4231_audio_getdev,
2066 cs4231_set_output_volume,
2067 cs4231_get_output_volume,
2068 cs4231_set_input_volume,
2069 cs4231_get_input_volume,
2070 cs4231_set_monitor_volume,
2071 cs4231_get_monitor_volume,
2072 cs4231_set_output_balance,
2073 cs4231_get_output_balance,
2074 cs4231_set_input_balance,
2075 cs4231_get_input_balance,
2076 cs4231_set_output_channels,
2077 cs4231_get_output_channels,
2078 cs4231_set_input_channels,
2079 cs4231_get_input_channels,
2080 cs4231_set_output_precision,
2081 cs4231_get_output_precision,
2082 cs4231_set_input_precision,
2083 cs4231_get_input_precision,
2084 cs4231_set_output_port,
2085 cs4231_get_output_port,
2086 cs4231_set_input_port,
2087 cs4231_get_input_port,
2088 cs4231_set_output_encoding,
2089 cs4231_get_output_encoding,
2090 cs4231_set_input_encoding,
2091 cs4231_get_input_encoding,
2092 cs4231_set_output_rate,
2093 cs4231_get_output_rate,
2094 cs4231_set_input_rate,
2095 cs4231_get_input_rate,
2096 cs4231_audio_getdev_sunos,
2097 cs4231_get_output_ports,
2098 cs4231_get_input_ports,
2099 cs4231_output_muted,
2100 cs4231_get_output_muted,
2101 cs4231_set_output_pause,
2102 cs4231_get_output_pause,
2103 cs4231_set_input_pause,
2104 cs4231_get_input_pause,
2105 cs4231_set_output_samples,
2106 cs4231_get_output_samples,
2107 cs4231_set_input_samples,
2108 cs4231_get_input_samples,
2109 cs4231_set_output_error,
2110 cs4231_get_output_error,
2111 cs4231_set_input_error,
2112 cs4231_get_input_error,
2116 #ifdef EB4231_SUPPORT
2117 static struct sparcaudio_operations eb4231_ops = {
2121 eb4231_start_output,
2125 cs4231_audio_getdev,
2126 cs4231_set_output_volume,
2127 cs4231_get_output_volume,
2128 cs4231_set_input_volume,
2129 cs4231_get_input_volume,
2130 cs4231_set_monitor_volume,
2131 cs4231_get_monitor_volume,
2132 cs4231_set_output_balance,
2133 cs4231_get_output_balance,
2134 cs4231_set_input_balance,
2135 cs4231_get_input_balance,
2136 cs4231_set_output_channels,
2137 cs4231_get_output_channels,
2138 cs4231_set_input_channels,
2139 cs4231_get_input_channels,
2140 cs4231_set_output_precision,
2141 cs4231_get_output_precision,
2142 cs4231_set_input_precision,
2143 cs4231_get_input_precision,
2144 cs4231_set_output_port,
2145 cs4231_get_output_port,
2146 cs4231_set_input_port,
2147 cs4231_get_input_port,
2148 cs4231_set_output_encoding,
2149 cs4231_get_output_encoding,
2150 cs4231_set_input_encoding,
2151 cs4231_get_input_encoding,
2152 cs4231_set_output_rate,
2153 cs4231_get_output_rate,
2154 cs4231_set_input_rate,
2155 cs4231_get_input_rate,
2156 cs4231_audio_getdev_sunos,
2157 cs4231_get_output_ports,
2158 cs4231_get_input_ports,
2159 cs4231_output_muted,
2160 cs4231_get_output_muted,
2161 cs4231_set_output_pause,
2162 cs4231_get_output_pause,
2163 cs4231_set_input_pause,
2164 cs4231_get_input_pause,
2165 cs4231_set_output_samples,
2166 eb4231_get_output_samples,
2167 cs4231_set_input_samples,
2168 eb4231_get_input_samples,
2169 cs4231_set_output_error,
2170 cs4231_get_output_error,
2171 cs4231_set_input_error,
2172 cs4231_get_input_error,
2177 /* Attach to an cs4231 chip given its PROM node. */
2178 static int cs4231_attach(struct sparcaudio_driver *drv,
2179 struct sbus_dev *sdev)
2181 #if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE < 0x20100
2182 struct linux_prom_irqs irq;
2184 struct cs4231_chip *cs4231_chip;
2187 /* Allocate our private information structure. */
2188 drv->private = kmalloc(sizeof(struct cs4231_chip), GFP_KERNEL);
2189 if (drv->private == NULL)
2192 /* Point at the information structure and initialize it. */
2193 drv->ops = &cs4231_ops;
2194 cs4231_chip = (struct cs4231_chip *) drv->private;
2195 cs4231_chip->input_ptr = cs4231_chip->output_ptr = NULL;
2196 cs4231_chip->input_size = cs4231_chip->output_size = 0;
2197 cs4231_chip->status = 0;
2201 /* Map the registers into memory. */
2202 cs4231_chip->regs_size = sdev->reg_addrs[0].reg_size;
2203 cs4231_chip->regs = sbus_ioremap(&sdev->resource[0], 0,
2204 sdev->reg_addrs[0].reg_size,
2207 if (!cs4231_chip->regs) {
2208 printk(KERN_ERR "cs4231: could not remap registers\n");
2209 kfree(drv->private);
2213 /* Attach the interrupt handler to the audio interrupt. */
2214 cs4231_chip->irq = sdev->irqs[0];
2215 request_irq(cs4231_chip->irq, cs4231_interrupt, SA_SHIRQ, "cs4231", drv);
2216 enable_irq(cs4231_chip->irq);
2218 cs4231_chip->nirqs = 1;
2219 cs4231_enable_interrupts(drv);
2221 /* Reset the audio chip. */
2222 cs4231_chip_reset(drv);
2224 /* Register ourselves with the midlevel audio driver. */
2225 err = register_sparcaudio_driver(drv, 1);
2228 printk(KERN_ERR "cs4231: unable to register\n");
2229 cs4231_disable_interrupts(drv);
2230 disable_irq(cs4231_chip->irq);
2231 free_irq(cs4231_chip->irq, drv);
2232 sbus_iounmap(cs4231_chip->regs, cs4231_chip->regs_size);
2233 kfree(drv->private);
2237 cs4231_chip->perchip_info.play.active =
2238 cs4231_chip->perchip_info.play.pause = 0;
2240 cs4231_chip->perchip_info.record.active =
2241 cs4231_chip->perchip_info.record.pause = 0;
2243 cs4231_chip->perchip_info.play.avail_ports = (AUDIO_HEADPHONE |
2247 cs4231_chip->perchip_info.record.avail_ports = (AUDIO_INTERNAL_CD_IN |
2250 AUDIO_ANALOG_LOOPBACK);
2252 /* Announce the hardware to the user. */
2253 printk(KERN_INFO "audio%d: cs4231%c at %lx irq %s\n",
2254 drv->index, (cs4231_chip->status & CS_STATUS_REV_A) ? 'a' : ' ',
2255 cs4231_chip->regs, __irq_itoa(cs4231_chip->irq));
2261 #ifdef EB4231_SUPPORT
2262 /* Attach to an cs4231 chip given its PROM node. */
2263 static int eb4231_attach(struct sparcaudio_driver *drv,
2264 struct linux_ebus_device *edev)
2266 struct cs4231_chip *cs4231_chip;
2267 int len, err, nregs;
2268 struct linux_prom_registers regs[4];
2270 /* Allocate our private information structure. */
2271 drv->private = kmalloc(sizeof(struct cs4231_chip), GFP_KERNEL);
2272 if (drv->private == NULL)
2275 /* Point at the information structure and initialize it. */
2276 drv->ops = &eb4231_ops;
2277 cs4231_chip = (struct cs4231_chip *) drv->private;
2278 cs4231_chip->input_ptr = cs4231_chip->output_ptr = NULL;
2279 cs4231_chip->input_size = cs4231_chip->output_size = 0;
2280 cs4231_chip->status = 0;
2282 drv->dev = (struct sbus_dev *)edev->bus->self;
2284 len = prom_getproperty(edev->prom_node, "reg", (void *)regs, sizeof(regs));
2285 if ((len % sizeof(regs[0])) != 0) {
2286 printk("eb4231: Strange reg property size %d\n", len);
2290 nregs = len / sizeof(regs[0]);
2291 cs4231_chip->regs = (unsigned long)ioremap(edev->resource[0].start, 0x10);
2292 cs4231_chip->eb2p = (unsigned long)ioremap(edev->resource[1].start, 0x10);
2293 cs4231_chip->eb2c = (unsigned long)ioremap(edev->resource[2].start, 0x10);
2295 cs4231_chip->status |= CS_STATUS_IS_EBUS;
2297 /* Attach the interrupt handler to the audio interrupt. */
2298 cs4231_chip->irq = edev->irqs[0];
2299 cs4231_chip->irq2 = edev->irqs[1];
2301 if(request_irq(cs4231_chip->irq, eb4231_cinterrupt, SA_SHIRQ, "cs4231", drv) ||
2302 request_irq(cs4231_chip->irq2, eb4231_pinterrupt, SA_SHIRQ, "cs4231", drv))
2305 cs4231_chip->nirqs = 2;
2306 cs4231_enable_interrupts(drv);
2308 /* Reset the audio chip. */
2309 cs4231_chip_reset(drv);
2311 /* Register ourselves with the midlevel audio driver. */
2312 err = register_sparcaudio_driver(drv, 1);
2316 printk(KERN_ERR "cs4231: unable to register\n");
2317 cs4231_disable_interrupts(drv);
2318 disable_irq(cs4231_chip->irq);
2319 free_irq(cs4231_chip->irq, drv);
2320 disable_irq(cs4231_chip->irq2);
2321 free_irq(cs4231_chip->irq2, drv);
2322 kfree(drv->private);
2326 cs4231_chip->perchip_info.play.active =
2327 cs4231_chip->perchip_info.play.pause = 0;
2329 cs4231_chip->perchip_info.record.active =
2330 cs4231_chip->perchip_info.record.pause = 0;
2332 cs4231_chip->perchip_info.play.avail_ports = (AUDIO_HEADPHONE |
2336 cs4231_chip->perchip_info.record.avail_ports = (AUDIO_INTERNAL_CD_IN |
2339 AUDIO_ANALOG_LOOPBACK);
2341 /* Announce the hardware to the user. */
2342 printk(KERN_INFO "audio%d: cs4231%c(eb2) at %lx irq %s\n",
2343 drv->index, (cs4231_chip->status & CS_STATUS_REV_A) ? 'a' : ' ',
2344 cs4231_chip->regs, __irq_itoa(cs4231_chip->irq));
2351 #ifdef EB4231_SUPPORT
2352 static int __init ebus_cs4231_p(struct linux_ebus_device *edev)
2354 if (!strcmp(edev->prom_name, "SUNW,CS4231"))
2356 if (!strcmp(edev->prom_name, "audio")) {
2359 prom_getstring(edev->prom_node, "compatible",
2360 compat, sizeof(compat));
2362 if (!strcmp(compat, "SUNW,CS4231"))
2370 /* Probe for the cs4231 chip and then attach the driver. */
2372 int init_module(void)
2374 int __init cs4231_init(void)
2377 struct sbus_bus *sbus;
2378 struct sbus_dev *sdev;
2379 #ifdef EB4231_SUPPORT
2380 struct linux_ebus *ebus;
2381 struct linux_ebus_device *edev;
2386 /* Probe each SBUS for cs4231 chips. */
2387 for_all_sbusdev(sdev, sbus) {
2388 if (!strcmp(sdev->prom_name, "SUNW,CS4231")) {
2389 /* Don't go over the max number of drivers. */
2390 if (num_drivers >= MAX_DRIVERS)
2393 if (cs4231_attach(&drivers[num_drivers], sdev) == 0)
2398 #ifdef EB4231_SUPPORT
2399 for_each_ebus(ebus) {
2400 for_each_ebusdev(edev, ebus) {
2401 if (ebus_cs4231_p(edev)) {
2402 /* Don't go over the max number of drivers. */
2403 if (num_drivers >= MAX_DRIVERS)
2406 if (eb4231_attach(&drivers[num_drivers], edev) == 0)
2413 /* Only return success if we found some cs4231 chips. */
2414 return (num_drivers > 0) ? 0 : -EIO;
2418 /* Detach from an cs4231 chip given the device structure. */
2419 static void cs4231_detach(struct sparcaudio_driver *drv)
2421 struct cs4231_chip *cs4231_chip = (struct cs4231_chip *) drv->private;
2423 cs4231_disable_interrupts(drv);
2424 unregister_sparcaudio_driver(drv, 1);
2425 disable_irq(cs4231_chip->irq);
2426 free_irq(cs4231_chip->irq, drv);
2427 if (!(cs4231_chip->status & CS_STATUS_IS_EBUS)) {
2428 sbus_iounmap(cs4231_chip->regs, cs4231_chip->regs_size);
2430 #ifdef EB4231_SUPPORT
2431 iounmap(cs4231_chip->regs);
2432 iounmap(cs4231_chip->eb2p);
2433 iounmap(cs4231_chip->eb2c);
2434 disable_irq(cs4231_chip->irq2);
2435 free_irq(cs4231_chip->irq2, drv);
2438 kfree(drv->private);
2441 void cleanup_module(void)
2445 for (i = 0; i < num_drivers; i++) {
2446 cs4231_detach(&drivers[i]);
2453 * Overrides for Emacs so that we follow Linus's tabbing style.
2454 * Emacs will notice this stuff at the end of the file and automatically
2455 * adjust the settings for this buffer only. This must remain at the end
2457 * ---------------------------------------------------------------------------
2460 * c-brace-imaginary-offset: 0
2461 * c-brace-offset: -4
2462 * c-argdecl-indent: 4
2463 * c-label-offset: -4
2464 * c-continued-statement-offset: 4
2465 * c-continued-brace-offset: 0
2466 * indent-tabs-mode: nil