2 * linux/sound/oss/waveartist.c
4 * The low level driver for the RWA010 Rockwell Wave Artist
5 * codec chip used in the Rebel.com NetWinder.
7 * Cleaned up and integrated into 2.1 by Russell King (rmk@arm.linux.org.uk)
8 * and Pat Beirne (patb@corel.ca)
11 * Copyright (C) by Rebel.com 1998-1999
13 * RWA010 specs received under NDA from Rockwell
15 * Copyright (C) by Hannu Savolainen 1993-1997
17 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
18 * Version 2 (June 1991). See the "COPYING" file distributed with this software
22 * 11-10-2000 Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
23 * Added __init to waveartist_init()
31 #define DEBUG_MIXER 16
32 #define DEBUG_TRIGGER 32
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/slab.h>
39 #include <linux/sched.h>
40 #include <linux/interrupt.h>
41 #include <linux/delay.h>
42 #include <linux/spinlock.h>
43 #include <linux/bitops.h>
45 #include <asm/system.h>
47 #include "sound_config.h"
48 #include "waveartist.h"
51 #include <mach/hardware.h>
52 #include <asm/mach-types.h>
59 #define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH |\
68 static unsigned short levels
[SOUND_MIXER_NRDEVICES
] = {
69 0x5555, /* Master Volume */
72 0x2323, /* Synth (FM) */
74 0x6464, /* PC Speaker */
75 0x0000, /* Ext Line */
78 0x6464, /* Recording monitor */
79 0x0000, /* SB PCM (ALT PCM) */
80 0x0000, /* Recording level */
81 0x6464, /* Input gain */
82 0x6464, /* Output gain */
83 0x0000, /* Line1 (Aux1) */
84 0x0000, /* Line2 (Aux2) */
85 0x0000, /* Line3 (Aux3) */
86 0x0000, /* Digital1 */
87 0x0000, /* Digital2 */
88 0x0000, /* Digital3 */
89 0x0000, /* Phone In */
90 0x6464, /* Phone Out */
97 struct address_info hw
; /* hardware */
108 /* Mixer parameters */
109 const struct waveartist_mixer_info
*mix
;
111 unsigned short *levels
; /* cache of volume settings */
112 int recmask
; /* currently enabled recording device! */
114 #ifdef CONFIG_ARCH_NETWINDER
115 signed int slider_vol
; /* hardware slider volume */
116 unsigned int handset_detect
:1;
117 unsigned int telephone_detect
:1;
118 unsigned int no_autoselect
:1;/* handset/telephone autoselects a path */
119 unsigned int spkr_mute_state
:1;/* set by ioctl or autoselect */
120 unsigned int line_mute_state
:1;/* set by ioctl or autoselect */
121 unsigned int use_slider
:1;/* use slider setting for o/p vol */
126 * This is the implementation specific mixer information.
128 struct waveartist_mixer_info
{
129 unsigned int supported_devs
; /* Supported devices */
130 unsigned int recording_devs
; /* Recordable devies */
131 unsigned int stereo_devs
; /* Stereo devices */
133 unsigned int (*select_input
)(wavnc_info
*, unsigned int,
134 unsigned char *, unsigned char *);
135 int (*decode_mixer
)(wavnc_info
*, int,
136 unsigned char, unsigned char);
137 int (*get_mixer
)(wavnc_info
*, int);
140 typedef struct wavnc_port_info
{
147 static int nr_waveartist_devs
;
148 static wavnc_info adev_info
[MAX_AUDIO_DEV
];
149 static DEFINE_SPINLOCK(waveartist_lock
);
151 #ifndef CONFIG_ARCH_NETWINDER
152 #define machine_is_netwinder() 0
154 static struct timer_list vnc_timer
;
155 static void vnc_configure_mixer(wavnc_info
*devc
, unsigned int input_mask
);
156 static int vnc_private_ioctl(int dev
, unsigned int cmd
, int __user
*arg
);
157 static void vnc_slider_tick(unsigned long data
);
161 waveartist_set_ctlr(struct address_info
*hw
, unsigned char clear
, unsigned char set
)
163 unsigned int ctlr_port
= hw
->io_base
+ CTLR
;
165 clear
= ~clear
& inb(ctlr_port
);
167 outb(clear
| set
, ctlr_port
);
170 /* Toggle IRQ acknowledge line
173 waveartist_iack(wavnc_info
*devc
)
175 unsigned int ctlr_port
= devc
->hw
.io_base
+ CTLR
;
178 old_ctlr
= inb(ctlr_port
) & ~IRQ_ACK
;
180 outb(old_ctlr
| IRQ_ACK
, ctlr_port
);
181 outb(old_ctlr
, ctlr_port
);
185 waveartist_sleep(int timeout_ms
)
187 unsigned int timeout
= msecs_to_jiffies(timeout_ms
*100);
188 return schedule_timeout_interruptible(timeout
);
192 waveartist_reset(wavnc_info
*devc
)
194 struct address_info
*hw
= &devc
->hw
;
195 unsigned int timeout
, res
= -1;
197 waveartist_set_ctlr(hw
, -1, RESET
);
199 waveartist_set_ctlr(hw
, RESET
, 0);
205 if (inb(hw
->io_base
+ STATR
) & CMD_RF
) {
206 res
= inw(hw
->io_base
+ CMDR
);
213 printk(KERN_WARNING
"WaveArtist: reset timeout ");
214 if (res
!= (unsigned int)-1)
215 printk("(res=%04X)", res
);
222 /* Helper function to send and receive words
223 * from WaveArtist. It handles all the handshaking
224 * and can send or receive multiple words.
227 waveartist_cmd(wavnc_info
*devc
,
228 int nr_cmd
, unsigned int *cmd
,
229 int nr_resp
, unsigned int *resp
)
231 unsigned int io_base
= devc
->hw
.io_base
;
232 unsigned int timed_out
= 0;
235 if (debug_flg
& DEBUG_CMD
) {
236 printk("waveartist_cmd: cmd=");
238 for (i
= 0; i
< nr_cmd
; i
++)
239 printk("%04X ", cmd
[i
]);
244 if (inb(io_base
+ STATR
) & CMD_RF
) {
250 old_data
= inw(io_base
+ CMDR
);
252 if (debug_flg
& DEBUG_CMD
)
253 printk("flushed %04X...", old_data
);
258 for (i
= 0; !timed_out
&& i
< nr_cmd
; i
++) {
261 for (count
= 5000; count
; count
--)
262 if (inb(io_base
+ STATR
) & CMD_WE
)
268 outw(cmd
[i
], io_base
+ CMDR
);
271 for (i
= 0; !timed_out
&& i
< nr_resp
; i
++) {
274 for (count
= 5000; count
; count
--)
275 if (inb(io_base
+ STATR
) & CMD_RF
)
281 resp
[i
] = inw(io_base
+ CMDR
);
284 if (debug_flg
& DEBUG_CMD
) {
286 printk("waveartist_cmd: resp=");
288 for (i
= 0; i
< nr_resp
; i
++)
289 printk("%04X ", resp
[i
]);
293 printk("waveartist_cmd: timed out\n");
296 return timed_out
? 1 : 0;
300 * Send one command word
303 waveartist_cmd1(wavnc_info
*devc
, unsigned int cmd
)
305 return waveartist_cmd(devc
, 1, &cmd
, 0, NULL
);
309 * Send one command, receive one word
311 static inline unsigned int
312 waveartist_cmd1_r(wavnc_info
*devc
, unsigned int cmd
)
316 waveartist_cmd(devc
, 1, &cmd
, 1, &ret
);
322 * Send a double command, receive one
323 * word (and throw it away)
326 waveartist_cmd2(wavnc_info
*devc
, unsigned int cmd
, unsigned int arg
)
328 unsigned int vals
[2];
333 return waveartist_cmd(devc
, 2, vals
, 1, vals
);
337 * Send a triple command
340 waveartist_cmd3(wavnc_info
*devc
, unsigned int cmd
,
341 unsigned int arg1
, unsigned int arg2
)
343 unsigned int vals
[3];
349 return waveartist_cmd(devc
, 3, vals
, 0, NULL
);
353 waveartist_getrev(wavnc_info
*devc
, char *rev
)
355 unsigned int temp
[2];
356 unsigned int cmd
= WACMD_GETREV
;
358 waveartist_cmd(devc
, 1, &cmd
, 2, temp
);
360 rev
[0] = temp
[0] >> 8;
361 rev
[1] = temp
[0] & 255;
367 static void waveartist_halt_output(int dev
);
368 static void waveartist_halt_input(int dev
);
369 static void waveartist_halt(int dev
);
370 static void waveartist_trigger(int dev
, int state
);
373 waveartist_open(int dev
, int mode
)
376 wavnc_port_info
*portc
;
379 if (dev
< 0 || dev
>= num_audiodevs
)
382 devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
383 portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
385 spin_lock_irqsave(&waveartist_lock
, flags
);
386 if (portc
->open_mode
|| (devc
->open_mode
& mode
)) {
387 spin_unlock_irqrestore(&waveartist_lock
, flags
);
391 devc
->audio_mode
= 0;
392 devc
->open_mode
|= mode
;
393 portc
->open_mode
= mode
;
394 waveartist_trigger(dev
, 0);
396 if (mode
& OPEN_READ
)
397 devc
->record_dev
= dev
;
398 if (mode
& OPEN_WRITE
)
399 devc
->playback_dev
= dev
;
400 spin_unlock_irqrestore(&waveartist_lock
, flags
);
406 waveartist_close(int dev
)
408 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
409 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
412 spin_lock_irqsave(&waveartist_lock
, flags
);
414 waveartist_halt(dev
);
416 devc
->audio_mode
= 0;
417 devc
->open_mode
&= ~portc
->open_mode
;
418 portc
->open_mode
= 0;
420 spin_unlock_irqrestore(&waveartist_lock
, flags
);
424 waveartist_output_block(int dev
, unsigned long buf
, int __count
, int intrflag
)
426 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
427 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
429 unsigned int count
= __count
;
431 if (debug_flg
& DEBUG_OUT
)
432 printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
437 if (portc
->audio_format
& (AFMT_S16_LE
| AFMT_S16_BE
))
440 if (portc
->channels
> 1)
445 if (devc
->audio_mode
& PCM_ENABLE_OUTPUT
&&
446 audio_devs
[dev
]->flags
& DMA_AUTOMODE
&&
448 count
== devc
->xfer_count
) {
449 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
451 * Auto DMA mode on. No need to react
455 spin_lock_irqsave(&waveartist_lock
, flags
);
460 waveartist_cmd2(devc
, WACMD_OUTPUTSIZE
, count
);
462 devc
->xfer_count
= count
;
463 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
465 spin_unlock_irqrestore(&waveartist_lock
, flags
);
469 waveartist_start_input(int dev
, unsigned long buf
, int __count
, int intrflag
)
471 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
472 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
474 unsigned int count
= __count
;
476 if (debug_flg
& DEBUG_IN
)
477 printk("waveartist: start input, buf=0x%lx, count=0x%x...\n",
480 if (portc
->audio_format
& (AFMT_S16_LE
| AFMT_S16_BE
)) /* 16 bit data */
483 if (portc
->channels
> 1)
488 if (devc
->audio_mode
& PCM_ENABLE_INPUT
&&
489 audio_devs
[dev
]->flags
& DMA_AUTOMODE
&&
491 count
== devc
->xfer_count
) {
492 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
494 * Auto DMA mode on. No need to react
498 spin_lock_irqsave(&waveartist_lock
, flags
);
503 waveartist_cmd2(devc
, WACMD_INPUTSIZE
, count
);
505 devc
->xfer_count
= count
;
506 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
508 spin_unlock_irqrestore(&waveartist_lock
, flags
);
512 waveartist_ioctl(int dev
, unsigned int cmd
, void __user
* arg
)
518 waveartist_get_speed(wavnc_port_info
*portc
)
523 * program the speed, channels, bits
525 if (portc
->speed
== 8000)
527 else if (portc
->speed
== 11025)
529 else if (portc
->speed
== 22050)
531 else if (portc
->speed
== 44100)
535 * non-standard - just calculate
537 speed
= portc
->speed
<< 16;
539 speed
= (speed
/ 44100) & 65535;
546 waveartist_get_bits(wavnc_port_info
*portc
)
550 if (portc
->audio_format
== AFMT_S16_LE
)
552 else if (portc
->audio_format
== AFMT_S8
)
555 bits
= 2; //default AFMT_U8
561 waveartist_prepare_for_input(int dev
, int bsize
, int bcount
)
564 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
565 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
566 unsigned int speed
, bits
;
568 if (devc
->audio_mode
)
571 speed
= waveartist_get_speed(portc
);
572 bits
= waveartist_get_bits(portc
);
574 spin_lock_irqsave(&waveartist_lock
, flags
);
576 if (waveartist_cmd2(devc
, WACMD_INPUTFORMAT
, bits
))
577 printk(KERN_WARNING
"waveartist: error setting the "
578 "record format to %d\n", portc
->audio_format
);
580 if (waveartist_cmd2(devc
, WACMD_INPUTCHANNELS
, portc
->channels
))
581 printk(KERN_WARNING
"waveartist: error setting record "
582 "to %d channels\n", portc
->channels
);
585 * write cmd SetSampleSpeedTimeConstant
587 if (waveartist_cmd2(devc
, WACMD_INPUTSPEED
, speed
))
588 printk(KERN_WARNING
"waveartist: error setting the record "
589 "speed to %dHz.\n", portc
->speed
);
591 if (waveartist_cmd2(devc
, WACMD_INPUTDMA
, 1))
592 printk(KERN_WARNING
"waveartist: error setting the record "
593 "data path to 0x%X\n", 1);
595 if (waveartist_cmd2(devc
, WACMD_INPUTFORMAT
, bits
))
596 printk(KERN_WARNING
"waveartist: error setting the record "
597 "format to %d\n", portc
->audio_format
);
599 devc
->xfer_count
= 0;
600 spin_unlock_irqrestore(&waveartist_lock
, flags
);
601 waveartist_halt_input(dev
);
603 if (debug_flg
& DEBUG_INTR
) {
604 printk("WA CTLR reg: 0x%02X.\n",
605 inb(devc
->hw
.io_base
+ CTLR
));
606 printk("WA STAT reg: 0x%02X.\n",
607 inb(devc
->hw
.io_base
+ STATR
));
608 printk("WA IRQS reg: 0x%02X.\n",
609 inb(devc
->hw
.io_base
+ IRQSTAT
));
616 waveartist_prepare_for_output(int dev
, int bsize
, int bcount
)
619 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
620 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
621 unsigned int speed
, bits
;
624 * program the speed, channels, bits
626 speed
= waveartist_get_speed(portc
);
627 bits
= waveartist_get_bits(portc
);
629 spin_lock_irqsave(&waveartist_lock
, flags
);
631 if (waveartist_cmd2(devc
, WACMD_OUTPUTSPEED
, speed
) &&
632 waveartist_cmd2(devc
, WACMD_OUTPUTSPEED
, speed
))
633 printk(KERN_WARNING
"waveartist: error setting the playback "
634 "speed to %dHz.\n", portc
->speed
);
636 if (waveartist_cmd2(devc
, WACMD_OUTPUTCHANNELS
, portc
->channels
))
637 printk(KERN_WARNING
"waveartist: error setting the playback "
638 "to %d channels\n", portc
->channels
);
640 if (waveartist_cmd2(devc
, WACMD_OUTPUTDMA
, 0))
641 printk(KERN_WARNING
"waveartist: error setting the playback "
642 "data path to 0x%X\n", 0);
644 if (waveartist_cmd2(devc
, WACMD_OUTPUTFORMAT
, bits
))
645 printk(KERN_WARNING
"waveartist: error setting the playback "
646 "format to %d\n", portc
->audio_format
);
648 devc
->xfer_count
= 0;
649 spin_unlock_irqrestore(&waveartist_lock
, flags
);
650 waveartist_halt_output(dev
);
652 if (debug_flg
& DEBUG_INTR
) {
653 printk("WA CTLR reg: 0x%02X.\n",inb(devc
->hw
.io_base
+ CTLR
));
654 printk("WA STAT reg: 0x%02X.\n",inb(devc
->hw
.io_base
+ STATR
));
655 printk("WA IRQS reg: 0x%02X.\n",inb(devc
->hw
.io_base
+ IRQSTAT
));
662 waveartist_halt(int dev
)
664 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
667 if (portc
->open_mode
& OPEN_WRITE
)
668 waveartist_halt_output(dev
);
670 if (portc
->open_mode
& OPEN_READ
)
671 waveartist_halt_input(dev
);
673 devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
674 devc
->audio_mode
= 0;
678 waveartist_halt_input(int dev
)
680 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
683 spin_lock_irqsave(&waveartist_lock
, flags
);
688 waveartist_cmd1(devc
, WACMD_INPUTSTOP
);
690 devc
->audio_mode
&= ~PCM_ENABLE_INPUT
;
693 * Clear interrupt by toggling
694 * the IRQ_ACK bit in CTRL
696 if (inb(devc
->hw
.io_base
+ STATR
) & IRQ_REQ
)
697 waveartist_iack(devc
);
699 // devc->audio_mode &= ~PCM_ENABLE_INPUT;
701 spin_unlock_irqrestore(&waveartist_lock
, flags
);
705 waveartist_halt_output(int dev
)
707 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
710 spin_lock_irqsave(&waveartist_lock
, flags
);
712 waveartist_cmd1(devc
, WACMD_OUTPUTSTOP
);
714 devc
->audio_mode
&= ~PCM_ENABLE_OUTPUT
;
717 * Clear interrupt by toggling
718 * the IRQ_ACK bit in CTRL
720 if (inb(devc
->hw
.io_base
+ STATR
) & IRQ_REQ
)
721 waveartist_iack(devc
);
723 // devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
725 spin_unlock_irqrestore(&waveartist_lock
, flags
);
729 waveartist_trigger(int dev
, int state
)
731 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
732 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
735 if (debug_flg
& DEBUG_TRIGGER
) {
736 printk("wavnc: audio trigger ");
737 if (state
& PCM_ENABLE_INPUT
)
739 if (state
& PCM_ENABLE_OUTPUT
)
744 spin_lock_irqsave(&waveartist_lock
, flags
);
746 state
&= devc
->audio_mode
;
748 if (portc
->open_mode
& OPEN_READ
&&
749 state
& PCM_ENABLE_INPUT
)
751 * enable ADC Data Transfer to PC
753 waveartist_cmd1(devc
, WACMD_INPUTSTART
);
755 if (portc
->open_mode
& OPEN_WRITE
&&
756 state
& PCM_ENABLE_OUTPUT
)
758 * enable DAC data transfer from PC
760 waveartist_cmd1(devc
, WACMD_OUTPUTSTART
);
762 spin_unlock_irqrestore(&waveartist_lock
, flags
);
766 waveartist_set_speed(int dev
, int arg
)
768 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
784 waveartist_set_channels(int dev
, short arg
)
786 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
788 if (arg
!= 1 && arg
!= 2)
789 return portc
->channels
;
791 portc
->channels
= arg
;
796 waveartist_set_bits(int dev
, unsigned int arg
)
798 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
801 return portc
->audio_format
;
803 if ((arg
!= AFMT_U8
) && (arg
!= AFMT_S16_LE
) && (arg
!= AFMT_S8
))
806 portc
->audio_format
= arg
;
811 static struct audio_driver waveartist_audio_driver
= {
812 .owner
= THIS_MODULE
,
813 .open
= waveartist_open
,
814 .close
= waveartist_close
,
815 .output_block
= waveartist_output_block
,
816 .start_input
= waveartist_start_input
,
817 .ioctl
= waveartist_ioctl
,
818 .prepare_for_input
= waveartist_prepare_for_input
,
819 .prepare_for_output
= waveartist_prepare_for_output
,
820 .halt_io
= waveartist_halt
,
821 .halt_input
= waveartist_halt_input
,
822 .halt_output
= waveartist_halt_output
,
823 .trigger
= waveartist_trigger
,
824 .set_speed
= waveartist_set_speed
,
825 .set_bits
= waveartist_set_bits
,
826 .set_channels
= waveartist_set_channels
831 waveartist_intr(int irq
, void *dev_id
)
833 wavnc_info
*devc
= dev_id
;
834 int irqstatus
, status
;
836 spin_lock(&waveartist_lock
);
837 irqstatus
= inb(devc
->hw
.io_base
+ IRQSTAT
);
838 status
= inb(devc
->hw
.io_base
+ STATR
);
840 if (debug_flg
& DEBUG_INTR
)
841 printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
844 if (status
& IRQ_REQ
) /* Clear interrupt */
845 waveartist_iack(devc
);
847 printk(KERN_WARNING
"waveartist: unexpected interrupt\n");
849 if (irqstatus
& 0x01) {
854 if ((status
& DMA0
) && (devc
->audio_mode
& PCM_ENABLE_OUTPUT
)) {
855 DMAbuf_outputintr(devc
->playback_dev
, 1);
858 if ((status
& DMA1
) && (devc
->audio_mode
& PCM_ENABLE_INPUT
)) {
859 DMAbuf_inputintr(devc
->record_dev
);
863 printk(KERN_WARNING
"waveartist: Unknown interrupt\n");
866 // We do not use SB mode natively...
867 printk(KERN_WARNING
"waveartist: Unexpected SB interrupt...\n");
868 spin_unlock(&waveartist_lock
);
872 /* -------------------------------------------------------------------------
882 static const struct mix_ent mix_devs
[SOUND_MIXER_NRDEVICES
] = {
883 { 2, 6, 1, 7 }, /* SOUND_MIXER_VOLUME */
884 { 0, 0, 0, 0 }, /* SOUND_MIXER_BASS */
885 { 0, 0, 0, 0 }, /* SOUND_MIXER_TREBLE */
886 { 0, 0, 0, 0 }, /* SOUND_MIXER_SYNTH */
887 { 0, 0, 0, 0 }, /* SOUND_MIXER_PCM */
888 { 0, 0, 0, 0 }, /* SOUND_MIXER_SPEAKER */
889 { 0, 4, 6, 31 }, /* SOUND_MIXER_LINE */
890 { 2, 6, 4, 3 }, /* SOUND_MIXER_MIC */
891 { 0, 0, 0, 0 }, /* SOUND_MIXER_CD */
892 { 0, 0, 0, 0 }, /* SOUND_MIXER_IMIX */
893 { 0, 0, 0, 0 }, /* SOUND_MIXER_ALTPCM */
895 { 3, 7, 0, 10 }, /* SOUND_MIXER_RECLEV */
896 { 0, 0, 0, 0 }, /* SOUND_MIXER_IGAIN */
898 { 0, 0, 0, 0 }, /* SOUND_MIXER_RECLEV */
899 { 3, 7, 0, 7 }, /* SOUND_MIXER_IGAIN */
901 { 0, 0, 0, 0 }, /* SOUND_MIXER_OGAIN */
902 { 0, 4, 1, 31 }, /* SOUND_MIXER_LINE1 */
903 { 1, 5, 6, 31 }, /* SOUND_MIXER_LINE2 */
904 { 0, 0, 0, 0 }, /* SOUND_MIXER_LINE3 */
905 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL1 */
906 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL2 */
907 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL3 */
908 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEIN */
909 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEOUT */
910 { 0, 0, 0, 0 }, /* SOUND_MIXER_VIDEO */
911 { 0, 0, 0, 0 }, /* SOUND_MIXER_RADIO */
912 { 0, 0, 0, 0 } /* SOUND_MIXER_MONITOR */
916 waveartist_mixer_update(wavnc_info
*devc
, int whichDev
)
918 unsigned int lev_left
, lev_right
;
920 lev_left
= devc
->levels
[whichDev
] & 0xff;
921 lev_right
= devc
->levels
[whichDev
] >> 8;
928 #define SCALE(lev,max) ((lev) * (max) / 100)
930 if (machine_is_netwinder() && whichDev
== SOUND_MIXER_PHONEOUT
)
931 whichDev
= SOUND_MIXER_VOLUME
;
933 if (mix_devs
[whichDev
].reg_l
|| mix_devs
[whichDev
].reg_r
) {
934 const struct mix_ent
*mix
= mix_devs
+ whichDev
;
935 unsigned int mask
, left
, right
;
937 mask
= mix
->max
<< mix
->shift
;
938 lev_left
= SCALE(lev_left
, mix
->max
) << mix
->shift
;
939 lev_right
= SCALE(lev_right
, mix
->max
) << mix
->shift
;
941 /* read left setting */
942 left
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
|
945 /* read right setting */
946 right
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
|
949 left
= (left
& ~mask
) | (lev_left
& mask
);
950 right
= (right
& ~mask
) | (lev_right
& mask
);
952 /* write left,right back */
953 waveartist_cmd3(devc
, WACMD_SET_MIXER
, left
, right
);
956 case SOUND_MIXER_PCM
:
957 waveartist_cmd3(devc
, WACMD_SET_LEVEL
,
958 SCALE(lev_left
, 32767),
959 SCALE(lev_right
, 32767));
962 case SOUND_MIXER_SYNTH
:
963 waveartist_cmd3(devc
, 0x0100 | WACMD_SET_LEVEL
,
964 SCALE(lev_left
, 32767),
965 SCALE(lev_right
, 32767));
972 * Set the ADC MUX to the specified values. We do NOT do any
973 * checking of the values passed, since we assume that the
974 * relevant *_select_input function has done that for us.
977 waveartist_set_adc_mux(wavnc_info
*devc
, char left_dev
, char right_dev
)
979 unsigned int reg_08
, reg_09
;
981 reg_08
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
| 0x0800);
982 reg_09
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
| 0x0900);
984 reg_08
= (reg_08
& ~0x3f) | right_dev
<< 3 | left_dev
;
986 waveartist_cmd3(devc
, WACMD_SET_MIXER
, reg_08
, reg_09
);
990 * Decode a recording mask into a mixer selection as follows:
992 * OSS Source WA Source Actual source
993 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
994 * SOUND_MASK_LINE Line Line in
995 * SOUND_MASK_LINE1 Aux 1 Aux 1 in
996 * SOUND_MASK_LINE2 Aux 2 Aux 2 in
997 * SOUND_MASK_MIC Mic Microphone
1000 waveartist_select_input(wavnc_info
*devc
, unsigned int recmask
,
1001 unsigned char *dev_l
, unsigned char *dev_r
)
1003 unsigned int recdev
= ADC_MUX_NONE
;
1005 if (recmask
& SOUND_MASK_IMIX
) {
1006 recmask
= SOUND_MASK_IMIX
;
1007 recdev
= ADC_MUX_MIXER
;
1008 } else if (recmask
& SOUND_MASK_LINE2
) {
1009 recmask
= SOUND_MASK_LINE2
;
1010 recdev
= ADC_MUX_AUX2
;
1011 } else if (recmask
& SOUND_MASK_LINE1
) {
1012 recmask
= SOUND_MASK_LINE1
;
1013 recdev
= ADC_MUX_AUX1
;
1014 } else if (recmask
& SOUND_MASK_LINE
) {
1015 recmask
= SOUND_MASK_LINE
;
1016 recdev
= ADC_MUX_LINE
;
1017 } else if (recmask
& SOUND_MASK_MIC
) {
1018 recmask
= SOUND_MASK_MIC
;
1019 recdev
= ADC_MUX_MIC
;
1022 *dev_l
= *dev_r
= recdev
;
1028 waveartist_decode_mixer(wavnc_info
*devc
, int dev
, unsigned char lev_l
,
1029 unsigned char lev_r
)
1032 case SOUND_MIXER_VOLUME
:
1033 case SOUND_MIXER_SYNTH
:
1034 case SOUND_MIXER_PCM
:
1035 case SOUND_MIXER_LINE
:
1036 case SOUND_MIXER_MIC
:
1037 case SOUND_MIXER_IGAIN
:
1038 case SOUND_MIXER_LINE1
:
1039 case SOUND_MIXER_LINE2
:
1040 devc
->levels
[dev
] = lev_l
| lev_r
<< 8;
1043 case SOUND_MIXER_IMIX
:
1054 static int waveartist_get_mixer(wavnc_info
*devc
, int dev
)
1056 return devc
->levels
[dev
];
1059 static const struct waveartist_mixer_info waveartist_mixer
= {
1060 .supported_devs
= SUPPORTED_MIXER_DEVICES
| SOUND_MASK_IGAIN
,
1061 .recording_devs
= SOUND_MASK_LINE
| SOUND_MASK_MIC
|
1062 SOUND_MASK_LINE1
| SOUND_MASK_LINE2
|
1064 .stereo_devs
= (SUPPORTED_MIXER_DEVICES
| SOUND_MASK_IGAIN
) & ~
1065 (SOUND_MASK_SPEAKER
| SOUND_MASK_IMIX
),
1066 .select_input
= waveartist_select_input
,
1067 .decode_mixer
= waveartist_decode_mixer
,
1068 .get_mixer
= waveartist_get_mixer
,
1072 waveartist_set_recmask(wavnc_info
*devc
, unsigned int recmask
)
1074 unsigned char dev_l
, dev_r
;
1076 recmask
&= devc
->mix
->recording_devs
;
1079 * If more than one recording device selected,
1080 * disable the device that is currently in use.
1082 if (hweight32(recmask
) > 1)
1083 recmask
&= ~devc
->recmask
;
1086 * Translate the recording device mask into
1087 * the ADC multiplexer settings.
1089 devc
->recmask
= devc
->mix
->select_input(devc
, recmask
,
1092 waveartist_set_adc_mux(devc
, dev_l
, dev_r
);
1096 waveartist_set_mixer(wavnc_info
*devc
, int dev
, unsigned int level
)
1098 unsigned int lev_left
= level
& 0x00ff;
1099 unsigned int lev_right
= (level
& 0xff00) >> 8;
1103 if (lev_right
> 100)
1107 * Mono devices have their right volume forced to their
1108 * left volume. (from ALSA driver OSS emulation).
1110 if (!(devc
->mix
->stereo_devs
& (1 << dev
)))
1111 lev_right
= lev_left
;
1113 dev
= devc
->mix
->decode_mixer(devc
, dev
, lev_left
, lev_right
);
1116 waveartist_mixer_update(devc
, dev
);
1118 return dev
< 0 ? dev
: 0;
1122 waveartist_mixer_ioctl(int dev
, unsigned int cmd
, void __user
* arg
)
1124 wavnc_info
*devc
= (wavnc_info
*)audio_devs
[dev
]->devc
;
1125 int ret
= 0, val
, nr
;
1128 * All SOUND_MIXER_* ioctls use type 'M'
1130 if (((cmd
>> 8) & 255) != 'M')
1131 return -ENOIOCTLCMD
;
1133 #ifdef CONFIG_ARCH_NETWINDER
1134 if (machine_is_netwinder()) {
1135 ret
= vnc_private_ioctl(dev
, cmd
, arg
);
1136 if (ret
!= -ENOIOCTLCMD
)
1145 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
) {
1146 if (get_user(val
, (int __user
*)arg
))
1150 case SOUND_MIXER_RECSRC
:
1151 waveartist_set_recmask(devc
, val
);
1156 if (nr
< SOUND_MIXER_NRDEVICES
&&
1157 devc
->mix
->supported_devs
& (1 << nr
))
1158 ret
= waveartist_set_mixer(devc
, nr
, val
);
1162 if (ret
== 0 && _SIOC_DIR(cmd
) & _SIOC_READ
) {
1166 case SOUND_MIXER_RECSRC
:
1167 ret
= devc
->recmask
;
1170 case SOUND_MIXER_DEVMASK
:
1171 ret
= devc
->mix
->supported_devs
;
1174 case SOUND_MIXER_STEREODEVS
:
1175 ret
= devc
->mix
->stereo_devs
;
1178 case SOUND_MIXER_RECMASK
:
1179 ret
= devc
->mix
->recording_devs
;
1182 case SOUND_MIXER_CAPS
:
1183 ret
= SOUND_CAP_EXCL_INPUT
;
1187 if (nr
< SOUND_MIXER_NRDEVICES
)
1188 ret
= devc
->mix
->get_mixer(devc
, nr
);
1193 ret
= put_user(ret
, (int __user
*)arg
) ? -EFAULT
: 0;
1199 static struct mixer_operations waveartist_mixer_operations
=
1201 .owner
= THIS_MODULE
,
1203 .name
= "WaveArtist",
1204 .ioctl
= waveartist_mixer_ioctl
1208 waveartist_mixer_reset(wavnc_info
*devc
)
1212 if (debug_flg
& DEBUG_MIXER
)
1213 printk("%s: mixer_reset\n", devc
->hw
.name
);
1218 waveartist_cmd1(devc
, WACMD_RST_MIXER
);
1221 * set input for ADC to come from 'quiet'
1222 * turn on default modes
1224 waveartist_cmd3(devc
, WACMD_SET_MIXER
, 0x9800, 0xa836);
1227 * set mixer input select to none, RX filter gains 0 dB
1229 waveartist_cmd3(devc
, WACMD_SET_MIXER
, 0x4c00, 0x8c00);
1232 * set bit 0 reg 2 to 1 - unmute MonoOut
1234 waveartist_cmd3(devc
, WACMD_SET_MIXER
, 0x2801, 0x6800);
1236 /* set default input device = internal mic
1237 * current recording device = none
1239 waveartist_set_recmask(devc
, 0);
1241 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
1242 waveartist_mixer_update(devc
, i
);
1245 static int __init
waveartist_init(wavnc_info
*devc
)
1247 wavnc_port_info
*portc
;
1248 char rev
[3], dev_name
[64];
1251 if (waveartist_reset(devc
))
1254 sprintf(dev_name
, "%s (%s", devc
->hw
.name
, devc
->chip_name
);
1256 if (waveartist_getrev(devc
, rev
)) {
1257 strcat(dev_name
, " rev. ");
1258 strcat(dev_name
, rev
);
1260 strcat(dev_name
, ")");
1262 conf_printf2(dev_name
, devc
->hw
.io_base
, devc
->hw
.irq
,
1263 devc
->hw
.dma
, devc
->hw
.dma2
);
1265 portc
= kzalloc(sizeof(wavnc_port_info
), GFP_KERNEL
);
1269 my_dev
= sound_install_audiodrv(AUDIO_DRIVER_VERSION
, dev_name
,
1270 &waveartist_audio_driver
, sizeof(struct audio_driver
),
1271 devc
->audio_flags
, AFMT_U8
| AFMT_S16_LE
| AFMT_S8
,
1272 devc
, devc
->hw
.dma
, devc
->hw
.dma2
);
1277 audio_devs
[my_dev
]->portc
= portc
;
1279 waveartist_mixer_reset(devc
);
1282 * clear any pending interrupt
1284 waveartist_iack(devc
);
1286 if (request_irq(devc
->hw
.irq
, waveartist_intr
, 0, devc
->hw
.name
, devc
) < 0) {
1287 printk(KERN_ERR
"%s: IRQ %d in use\n",
1288 devc
->hw
.name
, devc
->hw
.irq
);
1292 if (sound_alloc_dma(devc
->hw
.dma
, devc
->hw
.name
)) {
1293 printk(KERN_ERR
"%s: Can't allocate DMA%d\n",
1294 devc
->hw
.name
, devc
->hw
.dma
);
1298 if (devc
->hw
.dma
!= devc
->hw
.dma2
&& devc
->hw
.dma2
!= NO_DMA
)
1299 if (sound_alloc_dma(devc
->hw
.dma2
, devc
->hw
.name
)) {
1300 printk(KERN_ERR
"%s: can't allocate DMA%d\n",
1301 devc
->hw
.name
, devc
->hw
.dma2
);
1305 waveartist_set_ctlr(&devc
->hw
, 0, DMA1_IE
| DMA0_IE
);
1307 audio_devs
[my_dev
]->mixer_dev
=
1308 sound_install_mixer(MIXER_DRIVER_VERSION
,
1310 &waveartist_mixer_operations
,
1311 sizeof(struct mixer_operations
),
1317 sound_free_dma(devc
->hw
.dma
);
1320 free_irq(devc
->hw
.irq
, devc
);
1323 sound_unload_audiodev(my_dev
);
1332 static int __init
probe_waveartist(struct address_info
*hw_config
)
1334 wavnc_info
*devc
= &adev_info
[nr_waveartist_devs
];
1336 if (nr_waveartist_devs
>= MAX_AUDIO_DEV
) {
1337 printk(KERN_WARNING
"waveartist: too many audio devices\n");
1341 if (!request_region(hw_config
->io_base
, 15, hw_config
->name
)) {
1342 printk(KERN_WARNING
"WaveArtist: I/O port conflict\n");
1346 if (hw_config
->irq
> 15 || hw_config
->irq
< 0) {
1347 release_region(hw_config
->io_base
, 15);
1348 printk(KERN_WARNING
"WaveArtist: Bad IRQ %d\n",
1353 if (hw_config
->dma
!= 3) {
1354 release_region(hw_config
->io_base
, 15);
1355 printk(KERN_WARNING
"WaveArtist: Bad DMA %d\n",
1360 hw_config
->name
= "WaveArtist";
1361 devc
->hw
= *hw_config
;
1362 devc
->open_mode
= 0;
1363 devc
->chip_name
= "RWA-010";
1369 attach_waveartist(struct address_info
*hw
, const struct waveartist_mixer_info
*mix
)
1371 wavnc_info
*devc
= &adev_info
[nr_waveartist_devs
];
1374 * NOTE! If irq < 0, there is another driver which has allocated the
1375 * IRQ so that this driver doesn't need to allocate/deallocate it.
1376 * The actually used IRQ is ABS(irq).
1379 devc
->hw
.irq
= (hw
->irq
> 0) ? hw
->irq
: 0;
1380 devc
->open_mode
= 0;
1381 devc
->playback_dev
= 0;
1382 devc
->record_dev
= 0;
1383 devc
->audio_flags
= DMA_AUTOMODE
;
1384 devc
->levels
= levels
;
1386 if (hw
->dma
!= hw
->dma2
&& hw
->dma2
!= NO_DMA
)
1387 devc
->audio_flags
|= DMA_DUPLEX
;
1390 devc
->dev_no
= waveartist_init(devc
);
1392 if (devc
->dev_no
< 0)
1393 release_region(hw
->io_base
, 15);
1395 #ifdef CONFIG_ARCH_NETWINDER
1396 if (machine_is_netwinder()) {
1397 init_timer(&vnc_timer
);
1398 vnc_timer
.function
= vnc_slider_tick
;
1399 vnc_timer
.expires
= jiffies
;
1400 vnc_timer
.data
= nr_waveartist_devs
;
1401 add_timer(&vnc_timer
);
1403 vnc_configure_mixer(devc
, 0);
1405 devc
->no_autoselect
= 1;
1408 nr_waveartist_devs
+= 1;
1412 static void __exit
unload_waveartist(struct address_info
*hw
)
1414 wavnc_info
*devc
= NULL
;
1417 for (i
= 0; i
< nr_waveartist_devs
; i
++)
1418 if (hw
->io_base
== adev_info
[i
].hw
.io_base
) {
1419 devc
= adev_info
+ i
;
1426 #ifdef CONFIG_ARCH_NETWINDER
1427 if (machine_is_netwinder())
1428 del_timer(&vnc_timer
);
1431 release_region(devc
->hw
.io_base
, 15);
1433 waveartist_set_ctlr(&devc
->hw
, DMA1_IE
|DMA0_IE
, 0);
1435 if (devc
->hw
.irq
>= 0)
1436 free_irq(devc
->hw
.irq
, devc
);
1438 sound_free_dma(devc
->hw
.dma
);
1440 if (devc
->hw
.dma
!= devc
->hw
.dma2
&&
1441 devc
->hw
.dma2
!= NO_DMA
)
1442 sound_free_dma(devc
->hw
.dma2
);
1444 mixer
= audio_devs
[devc
->dev_no
]->mixer_dev
;
1447 sound_unload_mixerdev(mixer
);
1449 if (devc
->dev_no
>= 0)
1450 sound_unload_audiodev(devc
->dev_no
);
1452 nr_waveartist_devs
-= 1;
1454 for (; i
< nr_waveartist_devs
; i
++)
1455 adev_info
[i
] = adev_info
[i
+ 1];
1457 printk(KERN_WARNING
"waveartist: can't find device "
1461 #ifdef CONFIG_ARCH_NETWINDER
1464 * Rebel.com Netwinder specifics...
1467 #include <asm/hardware/dec21285.h>
1469 #define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
1471 #define MIXER_PRIVATE3_RESET 0x53570000
1472 #define MIXER_PRIVATE3_READ 0x53570001
1473 #define MIXER_PRIVATE3_WRITE 0x53570002
1475 #define VNC_MUTE_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
1476 #define VNC_MUTE_LINE_OUT 0x10
1477 #define VNC_PHONE_DETECT 0x20
1478 #define VNC_HANDSET_DETECT 0x40
1479 #define VNC_DISABLE_AUTOSWITCH 0x80
1482 vnc_mute_spkr(wavnc_info
*devc
)
1484 unsigned long flags
;
1486 spin_lock_irqsave(&nw_gpio_lock
, flags
);
1487 nw_cpld_modify(CPLD_UNMUTE
, devc
->spkr_mute_state
? 0 : CPLD_UNMUTE
);
1488 spin_unlock_irqrestore(&nw_gpio_lock
, flags
);
1492 vnc_mute_lout(wavnc_info
*devc
)
1494 unsigned int left
, right
;
1496 left
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
);
1497 right
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
| 0x400);
1499 if (devc
->line_mute_state
) {
1506 waveartist_cmd3(devc
, WACMD_SET_MIXER
, left
, right
);
1511 vnc_volume_slider(wavnc_info
*devc
)
1513 static signed int old_slider_volume
;
1514 unsigned long flags
;
1515 signed int volume
= 255;
1517 *CSR_TIMER1_LOAD
= 0x00ffffff;
1519 spin_lock_irqsave(&waveartist_lock
, flags
);
1522 *CSR_TIMER1_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_DIV1
;
1524 while (volume
&& (inb(0x201) & 0x01))
1527 *CSR_TIMER1_CNTL
= 0;
1529 spin_unlock_irqrestore(&waveartist_lock
,flags
);
1531 volume
= 0x00ffffff - *CSR_TIMER1_VALUE
;
1535 volume
= 150 - (volume
>> 5);
1537 volume
= (volume
>> 6) - 25;
1547 * slider quite often reads +-8, so debounce this random noise
1549 if (abs(volume
- old_slider_volume
) > 7) {
1550 old_slider_volume
= volume
;
1552 if (debug_flg
& DEBUG_MIXER
)
1553 printk(KERN_DEBUG
"Slider volume: %d.\n", volume
);
1556 return old_slider_volume
;
1560 * Decode a recording mask into a mixer selection on the NetWinder
1563 * OSS Source WA Source Actual source
1564 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
1565 * SOUND_MASK_LINE Line Line in
1566 * SOUND_MASK_LINE1 Left Mic Handset
1567 * SOUND_MASK_PHONEIN Left Aux Telephone microphone
1568 * SOUND_MASK_MIC Right Mic Builtin microphone
1571 netwinder_select_input(wavnc_info
*devc
, unsigned int recmask
,
1572 unsigned char *dev_l
, unsigned char *dev_r
)
1574 unsigned int recdev_l
= ADC_MUX_NONE
, recdev_r
= ADC_MUX_NONE
;
1576 if (recmask
& SOUND_MASK_IMIX
) {
1577 recmask
= SOUND_MASK_IMIX
;
1578 recdev_l
= ADC_MUX_MIXER
;
1579 recdev_r
= ADC_MUX_MIXER
;
1580 } else if (recmask
& SOUND_MASK_LINE
) {
1581 recmask
= SOUND_MASK_LINE
;
1582 recdev_l
= ADC_MUX_LINE
;
1583 recdev_r
= ADC_MUX_LINE
;
1584 } else if (recmask
& SOUND_MASK_LINE1
) {
1585 recmask
= SOUND_MASK_LINE1
;
1586 waveartist_cmd1(devc
, WACMD_SET_MONO
); /* left */
1587 recdev_l
= ADC_MUX_MIC
;
1588 recdev_r
= ADC_MUX_NONE
;
1589 } else if (recmask
& SOUND_MASK_PHONEIN
) {
1590 recmask
= SOUND_MASK_PHONEIN
;
1591 waveartist_cmd1(devc
, WACMD_SET_MONO
); /* left */
1592 recdev_l
= ADC_MUX_AUX1
;
1593 recdev_r
= ADC_MUX_NONE
;
1594 } else if (recmask
& SOUND_MASK_MIC
) {
1595 recmask
= SOUND_MASK_MIC
;
1596 waveartist_cmd1(devc
, WACMD_SET_MONO
| 0x100); /* right */
1597 recdev_l
= ADC_MUX_NONE
;
1598 recdev_r
= ADC_MUX_MIC
;
1608 netwinder_decode_mixer(wavnc_info
*devc
, int dev
, unsigned char lev_l
,
1609 unsigned char lev_r
)
1612 case SOUND_MIXER_VOLUME
:
1613 case SOUND_MIXER_SYNTH
:
1614 case SOUND_MIXER_PCM
:
1615 case SOUND_MIXER_LINE
:
1616 case SOUND_MIXER_IGAIN
:
1617 devc
->levels
[dev
] = lev_l
| lev_r
<< 8;
1620 case SOUND_MIXER_MIC
: /* right mic only */
1621 devc
->levels
[SOUND_MIXER_MIC
] &= 0xff;
1622 devc
->levels
[SOUND_MIXER_MIC
] |= lev_l
<< 8;
1625 case SOUND_MIXER_LINE1
: /* left mic only */
1626 devc
->levels
[SOUND_MIXER_MIC
] &= 0xff00;
1627 devc
->levels
[SOUND_MIXER_MIC
] |= lev_l
;
1628 dev
= SOUND_MIXER_MIC
;
1631 case SOUND_MIXER_PHONEIN
: /* left aux only */
1632 devc
->levels
[SOUND_MIXER_LINE1
] = lev_l
;
1633 dev
= SOUND_MIXER_LINE1
;
1636 case SOUND_MIXER_IMIX
:
1637 case SOUND_MIXER_PHONEOUT
:
1647 static int netwinder_get_mixer(wavnc_info
*devc
, int dev
)
1652 case SOUND_MIXER_VOLUME
:
1653 case SOUND_MIXER_SYNTH
:
1654 case SOUND_MIXER_PCM
:
1655 case SOUND_MIXER_LINE
:
1656 case SOUND_MIXER_IGAIN
:
1657 levels
= devc
->levels
[dev
];
1660 case SOUND_MIXER_MIC
: /* builtin mic: right mic only */
1661 levels
= devc
->levels
[SOUND_MIXER_MIC
] >> 8;
1662 levels
|= levels
<< 8;
1665 case SOUND_MIXER_LINE1
: /* handset mic: left mic only */
1666 levels
= devc
->levels
[SOUND_MIXER_MIC
] & 0xff;
1667 levels
|= levels
<< 8;
1670 case SOUND_MIXER_PHONEIN
: /* phone mic: left aux1 only */
1671 levels
= devc
->levels
[SOUND_MIXER_LINE1
] & 0xff;
1672 levels
|= levels
<< 8;
1683 * Waveartist specific mixer information.
1685 static const struct waveartist_mixer_info netwinder_mixer
= {
1686 .supported_devs
= SOUND_MASK_VOLUME
| SOUND_MASK_SYNTH
|
1687 SOUND_MASK_PCM
| SOUND_MASK_SPEAKER
|
1688 SOUND_MASK_LINE
| SOUND_MASK_MIC
|
1689 SOUND_MASK_IMIX
| SOUND_MASK_LINE1
|
1690 SOUND_MASK_PHONEIN
| SOUND_MASK_PHONEOUT
|
1693 .recording_devs
= SOUND_MASK_LINE
| SOUND_MASK_MIC
|
1694 SOUND_MASK_IMIX
| SOUND_MASK_LINE1
|
1697 .stereo_devs
= SOUND_MASK_VOLUME
| SOUND_MASK_SYNTH
|
1698 SOUND_MASK_PCM
| SOUND_MASK_LINE
|
1699 SOUND_MASK_IMIX
| SOUND_MASK_IGAIN
,
1701 .select_input
= netwinder_select_input
,
1702 .decode_mixer
= netwinder_decode_mixer
,
1703 .get_mixer
= netwinder_get_mixer
,
1707 vnc_configure_mixer(wavnc_info
*devc
, unsigned int recmask
)
1709 if (!devc
->no_autoselect
) {
1710 if (devc
->handset_detect
) {
1711 recmask
= SOUND_MASK_LINE1
;
1712 devc
->spkr_mute_state
= devc
->line_mute_state
= 1;
1713 } else if (devc
->telephone_detect
) {
1714 recmask
= SOUND_MASK_PHONEIN
;
1715 devc
->spkr_mute_state
= devc
->line_mute_state
= 1;
1717 /* unless someone has asked for LINE-IN,
1720 if ((devc
->recmask
& SOUND_MASK_LINE
) == 0)
1721 devc
->recmask
= SOUND_MASK_MIC
;
1722 devc
->spkr_mute_state
= devc
->line_mute_state
= 0;
1724 vnc_mute_spkr(devc
);
1725 vnc_mute_lout(devc
);
1727 if (recmask
!= devc
->recmask
)
1728 waveartist_set_recmask(devc
, recmask
);
1733 vnc_slider(wavnc_info
*devc
)
1735 signed int slider_volume
;
1736 unsigned int temp
, old_hs
, old_td
;
1739 * read the "buttons" state.
1740 * Bit 4 = 0 means handset present
1741 * Bit 5 = 1 means phone offhook
1745 old_hs
= devc
->handset_detect
;
1746 old_td
= devc
->telephone_detect
;
1748 devc
->handset_detect
= !(temp
& 0x10);
1749 devc
->telephone_detect
= !!(temp
& 0x20);
1751 if (!devc
->no_autoselect
&&
1752 (old_hs
!= devc
->handset_detect
||
1753 old_td
!= devc
->telephone_detect
))
1754 vnc_configure_mixer(devc
, devc
->recmask
);
1756 slider_volume
= vnc_volume_slider(devc
);
1759 * If we're using software controlled volume, and
1760 * the slider moves by more than 20%, then we
1761 * switch back to slider controlled volume.
1763 if (abs(devc
->slider_vol
- slider_volume
) > 20)
1764 devc
->use_slider
= 1;
1767 * use only left channel
1769 temp
= levels
[SOUND_MIXER_VOLUME
] & 0xFF;
1771 if (slider_volume
!= temp
&& devc
->use_slider
) {
1772 devc
->slider_vol
= slider_volume
;
1774 waveartist_set_mixer(devc
, SOUND_MIXER_VOLUME
,
1775 slider_volume
| slider_volume
<< 8);
1784 vnc_slider_tick(unsigned long data
)
1788 if (vnc_slider(adev_info
+ data
))
1789 next_timeout
= 5; // mixer reported change
1791 next_timeout
= VNC_TIMER_PERIOD
;
1793 mod_timer(&vnc_timer
, jiffies
+ next_timeout
);
1797 vnc_private_ioctl(int dev
, unsigned int cmd
, int __user
* arg
)
1799 wavnc_info
*devc
= (wavnc_info
*)audio_devs
[dev
]->devc
;
1803 case SOUND_MIXER_PRIVATE1
:
1805 u_int prev_spkr_mute
, prev_line_mute
, prev_auto_state
;
1808 if (get_user(val
, arg
))
1811 /* check if parameter is logical */
1812 if (val
& ~(VNC_MUTE_INTERNAL_SPKR
|
1814 VNC_DISABLE_AUTOSWITCH
))
1817 prev_auto_state
= devc
->no_autoselect
;
1818 prev_spkr_mute
= devc
->spkr_mute_state
;
1819 prev_line_mute
= devc
->line_mute_state
;
1821 devc
->no_autoselect
= (val
& VNC_DISABLE_AUTOSWITCH
) ? 1 : 0;
1822 devc
->spkr_mute_state
= (val
& VNC_MUTE_INTERNAL_SPKR
) ? 1 : 0;
1823 devc
->line_mute_state
= (val
& VNC_MUTE_LINE_OUT
) ? 1 : 0;
1825 if (prev_spkr_mute
!= devc
->spkr_mute_state
)
1826 vnc_mute_spkr(devc
);
1828 if (prev_line_mute
!= devc
->line_mute_state
)
1829 vnc_mute_lout(devc
);
1831 if (prev_auto_state
!= devc
->no_autoselect
)
1832 vnc_configure_mixer(devc
, devc
->recmask
);
1837 case SOUND_MIXER_PRIVATE2
:
1838 if (get_user(val
, arg
))
1842 #define VNC_SOUND_PAUSE 0x53 //to pause the DSP
1843 #define VNC_SOUND_RESUME 0x57 //to unpause the DSP
1844 case VNC_SOUND_PAUSE
:
1845 waveartist_cmd1(devc
, 0x16);
1848 case VNC_SOUND_RESUME
:
1849 waveartist_cmd1(devc
, 0x18);
1857 /* private ioctl to allow bulk access to waveartist */
1858 case SOUND_MIXER_PRIVATE3
:
1860 unsigned long flags
;
1861 int mixer_reg
[15], i
, val
;
1863 if (get_user(val
, arg
))
1865 if (copy_from_user(mixer_reg
, (void *)val
, sizeof(mixer_reg
)))
1868 switch (mixer_reg
[14]) {
1869 case MIXER_PRIVATE3_RESET
:
1870 waveartist_mixer_reset(devc
);
1873 case MIXER_PRIVATE3_WRITE
:
1874 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[0], mixer_reg
[4]);
1875 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[1], mixer_reg
[5]);
1876 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[2], mixer_reg
[6]);
1877 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[3], mixer_reg
[7]);
1878 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[8], mixer_reg
[9]);
1880 waveartist_cmd3(devc
, WACMD_SET_LEVEL
, mixer_reg
[10], mixer_reg
[11]);
1881 waveartist_cmd3(devc
, WACMD_SET_LEVEL
, mixer_reg
[12], mixer_reg
[13]);
1884 case MIXER_PRIVATE3_READ
:
1885 spin_lock_irqsave(&waveartist_lock
, flags
);
1887 for (i
= 0x30; i
< 14 << 8; i
+= 1 << 8)
1888 waveartist_cmd(devc
, 1, &i
, 1, mixer_reg
+ (i
>> 8));
1890 spin_unlock_irqrestore(&waveartist_lock
, flags
);
1892 if (copy_to_user((void *)val
, mixer_reg
, sizeof(mixer_reg
)))
1902 /* read back the state from PRIVATE1 */
1903 case SOUND_MIXER_PRIVATE4
:
1904 val
= (devc
->spkr_mute_state
? VNC_MUTE_INTERNAL_SPKR
: 0) |
1905 (devc
->line_mute_state
? VNC_MUTE_LINE_OUT
: 0) |
1906 (devc
->handset_detect
? VNC_HANDSET_DETECT
: 0) |
1907 (devc
->telephone_detect
? VNC_PHONE_DETECT
: 0) |
1908 (devc
->no_autoselect
? VNC_DISABLE_AUTOSWITCH
: 0);
1910 return put_user(val
, arg
) ? -EFAULT
: 0;
1913 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
) {
1915 * special case for master volume: if we
1916 * received this call - switch from hw
1917 * volume control to a software volume
1918 * control, till the hw volume is modified
1919 * to signal that user wants to be back in
1922 if ((cmd
& 0xff) == SOUND_MIXER_VOLUME
)
1923 devc
->use_slider
= 0;
1925 /* speaker output */
1926 if ((cmd
& 0xff) == SOUND_MIXER_SPEAKER
) {
1927 unsigned int val
, l
, r
;
1929 if (get_user(val
, arg
))
1933 r
= (val
& 0x7f00) >> 8;
1935 devc
->levels
[SOUND_MIXER_SPEAKER
] = val
| (val
<< 8);
1936 devc
->spkr_mute_state
= (val
<= 50);
1937 vnc_mute_spkr(devc
);
1942 return -ENOIOCTLCMD
;
1947 static struct address_info cfg
;
1949 static int attached
;
1951 static int __initdata io
= 0;
1952 static int __initdata irq
= 0;
1953 static int __initdata dma
= 0;
1954 static int __initdata dma2
= 0;
1957 static int __init
init_waveartist(void)
1959 const struct waveartist_mixer_info
*mix
;
1961 if (!io
&& machine_is_netwinder()) {
1963 * The NetWinder WaveArtist is at a fixed address.
1964 * If the user does not supply an address, use the
1965 * well-known parameters.
1973 mix
= &waveartist_mixer
;
1974 #ifdef CONFIG_ARCH_NETWINDER
1975 if (machine_is_netwinder())
1976 mix
= &netwinder_mixer
;
1984 if (!probe_waveartist(&cfg
))
1987 attach_waveartist(&cfg
, mix
);
1993 static void __exit
cleanup_waveartist(void)
1996 unload_waveartist(&cfg
);
1999 module_init(init_waveartist
);
2000 module_exit(cleanup_waveartist
);
2003 static int __init
setup_waveartist(char *str
)
2005 /* io, irq, dma, dma2 */
2008 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
2017 __setup("waveartist=", setup_waveartist
);
2020 MODULE_DESCRIPTION("Rockwell WaveArtist RWA-010 sound driver");
2021 module_param(io
, int, 0); /* IO base */
2022 module_param(irq
, int, 0); /* IRQ */
2023 module_param(dma
, int, 0); /* DMA */
2024 module_param(dma2
, int, 0); /* DMA2 */
2025 MODULE_LICENSE("GPL");