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>
46 #include "sound_config.h"
47 #include "waveartist.h"
50 #include <mach/hardware.h>
51 #include <asm/mach-types.h>
58 #define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH |\
67 static unsigned short levels
[SOUND_MIXER_NRDEVICES
] = {
68 0x5555, /* Master Volume */
71 0x2323, /* Synth (FM) */
73 0x6464, /* PC Speaker */
74 0x0000, /* Ext Line */
77 0x6464, /* Recording monitor */
78 0x0000, /* SB PCM (ALT PCM) */
79 0x0000, /* Recording level */
80 0x6464, /* Input gain */
81 0x6464, /* Output gain */
82 0x0000, /* Line1 (Aux1) */
83 0x0000, /* Line2 (Aux2) */
84 0x0000, /* Line3 (Aux3) */
85 0x0000, /* Digital1 */
86 0x0000, /* Digital2 */
87 0x0000, /* Digital3 */
88 0x0000, /* Phone In */
89 0x6464, /* Phone Out */
96 struct address_info hw
; /* hardware */
107 /* Mixer parameters */
108 const struct waveartist_mixer_info
*mix
;
110 unsigned short *levels
; /* cache of volume settings */
111 int recmask
; /* currently enabled recording device! */
113 #ifdef CONFIG_ARCH_NETWINDER
114 signed int slider_vol
; /* hardware slider volume */
115 unsigned int handset_detect
:1;
116 unsigned int telephone_detect
:1;
117 unsigned int no_autoselect
:1;/* handset/telephone autoselects a path */
118 unsigned int spkr_mute_state
:1;/* set by ioctl or autoselect */
119 unsigned int line_mute_state
:1;/* set by ioctl or autoselect */
120 unsigned int use_slider
:1;/* use slider setting for o/p vol */
125 * This is the implementation specific mixer information.
127 struct waveartist_mixer_info
{
128 unsigned int supported_devs
; /* Supported devices */
129 unsigned int recording_devs
; /* Recordable devies */
130 unsigned int stereo_devs
; /* Stereo devices */
132 unsigned int (*select_input
)(wavnc_info
*, unsigned int,
133 unsigned char *, unsigned char *);
134 int (*decode_mixer
)(wavnc_info
*, int,
135 unsigned char, unsigned char);
136 int (*get_mixer
)(wavnc_info
*, int);
139 typedef struct wavnc_port_info
{
146 static int nr_waveartist_devs
;
147 static wavnc_info adev_info
[MAX_AUDIO_DEV
];
148 static DEFINE_SPINLOCK(waveartist_lock
);
150 #ifndef CONFIG_ARCH_NETWINDER
151 #define machine_is_netwinder() 0
153 static struct timer_list vnc_timer
;
154 static void vnc_configure_mixer(wavnc_info
*devc
, unsigned int input_mask
);
155 static int vnc_private_ioctl(int dev
, unsigned int cmd
, int __user
*arg
);
156 static void vnc_slider_tick(unsigned long data
);
160 waveartist_set_ctlr(struct address_info
*hw
, unsigned char clear
, unsigned char set
)
162 unsigned int ctlr_port
= hw
->io_base
+ CTLR
;
164 clear
= ~clear
& inb(ctlr_port
);
166 outb(clear
| set
, ctlr_port
);
169 /* Toggle IRQ acknowledge line
172 waveartist_iack(wavnc_info
*devc
)
174 unsigned int ctlr_port
= devc
->hw
.io_base
+ CTLR
;
177 old_ctlr
= inb(ctlr_port
) & ~IRQ_ACK
;
179 outb(old_ctlr
| IRQ_ACK
, ctlr_port
);
180 outb(old_ctlr
, ctlr_port
);
184 waveartist_sleep(int timeout_ms
)
186 unsigned int timeout
= msecs_to_jiffies(timeout_ms
*100);
187 return schedule_timeout_interruptible(timeout
);
191 waveartist_reset(wavnc_info
*devc
)
193 struct address_info
*hw
= &devc
->hw
;
194 unsigned int timeout
, res
= -1;
196 waveartist_set_ctlr(hw
, -1, RESET
);
198 waveartist_set_ctlr(hw
, RESET
, 0);
204 if (inb(hw
->io_base
+ STATR
) & CMD_RF
) {
205 res
= inw(hw
->io_base
+ CMDR
);
212 printk(KERN_WARNING
"WaveArtist: reset timeout ");
213 if (res
!= (unsigned int)-1)
214 printk("(res=%04X)", res
);
221 /* Helper function to send and receive words
222 * from WaveArtist. It handles all the handshaking
223 * and can send or receive multiple words.
226 waveartist_cmd(wavnc_info
*devc
,
227 int nr_cmd
, unsigned int *cmd
,
228 int nr_resp
, unsigned int *resp
)
230 unsigned int io_base
= devc
->hw
.io_base
;
231 unsigned int timed_out
= 0;
234 if (debug_flg
& DEBUG_CMD
) {
235 printk("waveartist_cmd: cmd=");
237 for (i
= 0; i
< nr_cmd
; i
++)
238 printk("%04X ", cmd
[i
]);
243 if (inb(io_base
+ STATR
) & CMD_RF
) {
249 old_data
= inw(io_base
+ CMDR
);
251 if (debug_flg
& DEBUG_CMD
)
252 printk("flushed %04X...", old_data
);
257 for (i
= 0; !timed_out
&& i
< nr_cmd
; i
++) {
260 for (count
= 5000; count
; count
--)
261 if (inb(io_base
+ STATR
) & CMD_WE
)
267 outw(cmd
[i
], io_base
+ CMDR
);
270 for (i
= 0; !timed_out
&& i
< nr_resp
; i
++) {
273 for (count
= 5000; count
; count
--)
274 if (inb(io_base
+ STATR
) & CMD_RF
)
280 resp
[i
] = inw(io_base
+ CMDR
);
283 if (debug_flg
& DEBUG_CMD
) {
285 printk("waveartist_cmd: resp=");
287 for (i
= 0; i
< nr_resp
; i
++)
288 printk("%04X ", resp
[i
]);
292 printk("waveartist_cmd: timed out\n");
295 return timed_out
? 1 : 0;
299 * Send one command word
302 waveartist_cmd1(wavnc_info
*devc
, unsigned int cmd
)
304 return waveartist_cmd(devc
, 1, &cmd
, 0, NULL
);
308 * Send one command, receive one word
310 static inline unsigned int
311 waveartist_cmd1_r(wavnc_info
*devc
, unsigned int cmd
)
315 waveartist_cmd(devc
, 1, &cmd
, 1, &ret
);
321 * Send a double command, receive one
322 * word (and throw it away)
325 waveartist_cmd2(wavnc_info
*devc
, unsigned int cmd
, unsigned int arg
)
327 unsigned int vals
[2];
332 return waveartist_cmd(devc
, 2, vals
, 1, vals
);
336 * Send a triple command
339 waveartist_cmd3(wavnc_info
*devc
, unsigned int cmd
,
340 unsigned int arg1
, unsigned int arg2
)
342 unsigned int vals
[3];
348 return waveartist_cmd(devc
, 3, vals
, 0, NULL
);
352 waveartist_getrev(wavnc_info
*devc
, char *rev
)
354 unsigned int temp
[2];
355 unsigned int cmd
= WACMD_GETREV
;
357 waveartist_cmd(devc
, 1, &cmd
, 2, temp
);
359 rev
[0] = temp
[0] >> 8;
360 rev
[1] = temp
[0] & 255;
366 static void waveartist_halt_output(int dev
);
367 static void waveartist_halt_input(int dev
);
368 static void waveartist_halt(int dev
);
369 static void waveartist_trigger(int dev
, int state
);
372 waveartist_open(int dev
, int mode
)
375 wavnc_port_info
*portc
;
378 if (dev
< 0 || dev
>= num_audiodevs
)
381 devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
382 portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
384 spin_lock_irqsave(&waveartist_lock
, flags
);
385 if (portc
->open_mode
|| (devc
->open_mode
& mode
)) {
386 spin_unlock_irqrestore(&waveartist_lock
, flags
);
390 devc
->audio_mode
= 0;
391 devc
->open_mode
|= mode
;
392 portc
->open_mode
= mode
;
393 waveartist_trigger(dev
, 0);
395 if (mode
& OPEN_READ
)
396 devc
->record_dev
= dev
;
397 if (mode
& OPEN_WRITE
)
398 devc
->playback_dev
= dev
;
399 spin_unlock_irqrestore(&waveartist_lock
, flags
);
405 waveartist_close(int dev
)
407 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
408 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
411 spin_lock_irqsave(&waveartist_lock
, flags
);
413 waveartist_halt(dev
);
415 devc
->audio_mode
= 0;
416 devc
->open_mode
&= ~portc
->open_mode
;
417 portc
->open_mode
= 0;
419 spin_unlock_irqrestore(&waveartist_lock
, flags
);
423 waveartist_output_block(int dev
, unsigned long buf
, int __count
, int intrflag
)
425 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
426 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
428 unsigned int count
= __count
;
430 if (debug_flg
& DEBUG_OUT
)
431 printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
436 if (portc
->audio_format
& (AFMT_S16_LE
| AFMT_S16_BE
))
439 if (portc
->channels
> 1)
444 if (devc
->audio_mode
& PCM_ENABLE_OUTPUT
&&
445 audio_devs
[dev
]->flags
& DMA_AUTOMODE
&&
447 count
== devc
->xfer_count
) {
448 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
450 * Auto DMA mode on. No need to react
454 spin_lock_irqsave(&waveartist_lock
, flags
);
459 waveartist_cmd2(devc
, WACMD_OUTPUTSIZE
, count
);
461 devc
->xfer_count
= count
;
462 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
464 spin_unlock_irqrestore(&waveartist_lock
, flags
);
468 waveartist_start_input(int dev
, unsigned long buf
, int __count
, int intrflag
)
470 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
471 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
473 unsigned int count
= __count
;
475 if (debug_flg
& DEBUG_IN
)
476 printk("waveartist: start input, buf=0x%lx, count=0x%x...\n",
479 if (portc
->audio_format
& (AFMT_S16_LE
| AFMT_S16_BE
)) /* 16 bit data */
482 if (portc
->channels
> 1)
487 if (devc
->audio_mode
& PCM_ENABLE_INPUT
&&
488 audio_devs
[dev
]->flags
& DMA_AUTOMODE
&&
490 count
== devc
->xfer_count
) {
491 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
493 * Auto DMA mode on. No need to react
497 spin_lock_irqsave(&waveartist_lock
, flags
);
502 waveartist_cmd2(devc
, WACMD_INPUTSIZE
, count
);
504 devc
->xfer_count
= count
;
505 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
507 spin_unlock_irqrestore(&waveartist_lock
, flags
);
511 waveartist_ioctl(int dev
, unsigned int cmd
, void __user
* arg
)
517 waveartist_get_speed(wavnc_port_info
*portc
)
522 * program the speed, channels, bits
524 if (portc
->speed
== 8000)
526 else if (portc
->speed
== 11025)
528 else if (portc
->speed
== 22050)
530 else if (portc
->speed
== 44100)
534 * non-standard - just calculate
536 speed
= portc
->speed
<< 16;
538 speed
= (speed
/ 44100) & 65535;
545 waveartist_get_bits(wavnc_port_info
*portc
)
549 if (portc
->audio_format
== AFMT_S16_LE
)
551 else if (portc
->audio_format
== AFMT_S8
)
554 bits
= 2; //default AFMT_U8
560 waveartist_prepare_for_input(int dev
, int bsize
, int bcount
)
563 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
564 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
565 unsigned int speed
, bits
;
567 if (devc
->audio_mode
)
570 speed
= waveartist_get_speed(portc
);
571 bits
= waveartist_get_bits(portc
);
573 spin_lock_irqsave(&waveartist_lock
, flags
);
575 if (waveartist_cmd2(devc
, WACMD_INPUTFORMAT
, bits
))
576 printk(KERN_WARNING
"waveartist: error setting the "
577 "record format to %d\n", portc
->audio_format
);
579 if (waveartist_cmd2(devc
, WACMD_INPUTCHANNELS
, portc
->channels
))
580 printk(KERN_WARNING
"waveartist: error setting record "
581 "to %d channels\n", portc
->channels
);
584 * write cmd SetSampleSpeedTimeConstant
586 if (waveartist_cmd2(devc
, WACMD_INPUTSPEED
, speed
))
587 printk(KERN_WARNING
"waveartist: error setting the record "
588 "speed to %dHz.\n", portc
->speed
);
590 if (waveartist_cmd2(devc
, WACMD_INPUTDMA
, 1))
591 printk(KERN_WARNING
"waveartist: error setting the record "
592 "data path to 0x%X\n", 1);
594 if (waveartist_cmd2(devc
, WACMD_INPUTFORMAT
, bits
))
595 printk(KERN_WARNING
"waveartist: error setting the record "
596 "format to %d\n", portc
->audio_format
);
598 devc
->xfer_count
= 0;
599 spin_unlock_irqrestore(&waveartist_lock
, flags
);
600 waveartist_halt_input(dev
);
602 if (debug_flg
& DEBUG_INTR
) {
603 printk("WA CTLR reg: 0x%02X.\n",
604 inb(devc
->hw
.io_base
+ CTLR
));
605 printk("WA STAT reg: 0x%02X.\n",
606 inb(devc
->hw
.io_base
+ STATR
));
607 printk("WA IRQS reg: 0x%02X.\n",
608 inb(devc
->hw
.io_base
+ IRQSTAT
));
615 waveartist_prepare_for_output(int dev
, int bsize
, int bcount
)
618 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
619 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
620 unsigned int speed
, bits
;
623 * program the speed, channels, bits
625 speed
= waveartist_get_speed(portc
);
626 bits
= waveartist_get_bits(portc
);
628 spin_lock_irqsave(&waveartist_lock
, flags
);
630 if (waveartist_cmd2(devc
, WACMD_OUTPUTSPEED
, speed
) &&
631 waveartist_cmd2(devc
, WACMD_OUTPUTSPEED
, speed
))
632 printk(KERN_WARNING
"waveartist: error setting the playback "
633 "speed to %dHz.\n", portc
->speed
);
635 if (waveartist_cmd2(devc
, WACMD_OUTPUTCHANNELS
, portc
->channels
))
636 printk(KERN_WARNING
"waveartist: error setting the playback "
637 "to %d channels\n", portc
->channels
);
639 if (waveartist_cmd2(devc
, WACMD_OUTPUTDMA
, 0))
640 printk(KERN_WARNING
"waveartist: error setting the playback "
641 "data path to 0x%X\n", 0);
643 if (waveartist_cmd2(devc
, WACMD_OUTPUTFORMAT
, bits
))
644 printk(KERN_WARNING
"waveartist: error setting the playback "
645 "format to %d\n", portc
->audio_format
);
647 devc
->xfer_count
= 0;
648 spin_unlock_irqrestore(&waveartist_lock
, flags
);
649 waveartist_halt_output(dev
);
651 if (debug_flg
& DEBUG_INTR
) {
652 printk("WA CTLR reg: 0x%02X.\n",inb(devc
->hw
.io_base
+ CTLR
));
653 printk("WA STAT reg: 0x%02X.\n",inb(devc
->hw
.io_base
+ STATR
));
654 printk("WA IRQS reg: 0x%02X.\n",inb(devc
->hw
.io_base
+ IRQSTAT
));
661 waveartist_halt(int dev
)
663 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
666 if (portc
->open_mode
& OPEN_WRITE
)
667 waveartist_halt_output(dev
);
669 if (portc
->open_mode
& OPEN_READ
)
670 waveartist_halt_input(dev
);
672 devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
673 devc
->audio_mode
= 0;
677 waveartist_halt_input(int dev
)
679 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
682 spin_lock_irqsave(&waveartist_lock
, flags
);
687 waveartist_cmd1(devc
, WACMD_INPUTSTOP
);
689 devc
->audio_mode
&= ~PCM_ENABLE_INPUT
;
692 * Clear interrupt by toggling
693 * the IRQ_ACK bit in CTRL
695 if (inb(devc
->hw
.io_base
+ STATR
) & IRQ_REQ
)
696 waveartist_iack(devc
);
698 // devc->audio_mode &= ~PCM_ENABLE_INPUT;
700 spin_unlock_irqrestore(&waveartist_lock
, flags
);
704 waveartist_halt_output(int dev
)
706 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
709 spin_lock_irqsave(&waveartist_lock
, flags
);
711 waveartist_cmd1(devc
, WACMD_OUTPUTSTOP
);
713 devc
->audio_mode
&= ~PCM_ENABLE_OUTPUT
;
716 * Clear interrupt by toggling
717 * the IRQ_ACK bit in CTRL
719 if (inb(devc
->hw
.io_base
+ STATR
) & IRQ_REQ
)
720 waveartist_iack(devc
);
722 // devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
724 spin_unlock_irqrestore(&waveartist_lock
, flags
);
728 waveartist_trigger(int dev
, int state
)
730 wavnc_info
*devc
= (wavnc_info
*) audio_devs
[dev
]->devc
;
731 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
734 if (debug_flg
& DEBUG_TRIGGER
) {
735 printk("wavnc: audio trigger ");
736 if (state
& PCM_ENABLE_INPUT
)
738 if (state
& PCM_ENABLE_OUTPUT
)
743 spin_lock_irqsave(&waveartist_lock
, flags
);
745 state
&= devc
->audio_mode
;
747 if (portc
->open_mode
& OPEN_READ
&&
748 state
& PCM_ENABLE_INPUT
)
750 * enable ADC Data Transfer to PC
752 waveartist_cmd1(devc
, WACMD_INPUTSTART
);
754 if (portc
->open_mode
& OPEN_WRITE
&&
755 state
& PCM_ENABLE_OUTPUT
)
757 * enable DAC data transfer from PC
759 waveartist_cmd1(devc
, WACMD_OUTPUTSTART
);
761 spin_unlock_irqrestore(&waveartist_lock
, flags
);
765 waveartist_set_speed(int dev
, int arg
)
767 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
783 waveartist_set_channels(int dev
, short arg
)
785 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
787 if (arg
!= 1 && arg
!= 2)
788 return portc
->channels
;
790 portc
->channels
= arg
;
795 waveartist_set_bits(int dev
, unsigned int arg
)
797 wavnc_port_info
*portc
= (wavnc_port_info
*) audio_devs
[dev
]->portc
;
800 return portc
->audio_format
;
802 if ((arg
!= AFMT_U8
) && (arg
!= AFMT_S16_LE
) && (arg
!= AFMT_S8
))
805 portc
->audio_format
= arg
;
810 static struct audio_driver waveartist_audio_driver
= {
811 .owner
= THIS_MODULE
,
812 .open
= waveartist_open
,
813 .close
= waveartist_close
,
814 .output_block
= waveartist_output_block
,
815 .start_input
= waveartist_start_input
,
816 .ioctl
= waveartist_ioctl
,
817 .prepare_for_input
= waveartist_prepare_for_input
,
818 .prepare_for_output
= waveartist_prepare_for_output
,
819 .halt_io
= waveartist_halt
,
820 .halt_input
= waveartist_halt_input
,
821 .halt_output
= waveartist_halt_output
,
822 .trigger
= waveartist_trigger
,
823 .set_speed
= waveartist_set_speed
,
824 .set_bits
= waveartist_set_bits
,
825 .set_channels
= waveartist_set_channels
830 waveartist_intr(int irq
, void *dev_id
)
832 wavnc_info
*devc
= dev_id
;
833 int irqstatus
, status
;
835 spin_lock(&waveartist_lock
);
836 irqstatus
= inb(devc
->hw
.io_base
+ IRQSTAT
);
837 status
= inb(devc
->hw
.io_base
+ STATR
);
839 if (debug_flg
& DEBUG_INTR
)
840 printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
843 if (status
& IRQ_REQ
) /* Clear interrupt */
844 waveartist_iack(devc
);
846 printk(KERN_WARNING
"waveartist: unexpected interrupt\n");
848 if (irqstatus
& 0x01) {
853 if ((status
& DMA0
) && (devc
->audio_mode
& PCM_ENABLE_OUTPUT
)) {
854 DMAbuf_outputintr(devc
->playback_dev
, 1);
857 if ((status
& DMA1
) && (devc
->audio_mode
& PCM_ENABLE_INPUT
)) {
858 DMAbuf_inputintr(devc
->record_dev
);
862 printk(KERN_WARNING
"waveartist: Unknown interrupt\n");
865 // We do not use SB mode natively...
866 printk(KERN_WARNING
"waveartist: Unexpected SB interrupt...\n");
867 spin_unlock(&waveartist_lock
);
871 /* -------------------------------------------------------------------------
881 static const struct mix_ent mix_devs
[SOUND_MIXER_NRDEVICES
] = {
882 { 2, 6, 1, 7 }, /* SOUND_MIXER_VOLUME */
883 { 0, 0, 0, 0 }, /* SOUND_MIXER_BASS */
884 { 0, 0, 0, 0 }, /* SOUND_MIXER_TREBLE */
885 { 0, 0, 0, 0 }, /* SOUND_MIXER_SYNTH */
886 { 0, 0, 0, 0 }, /* SOUND_MIXER_PCM */
887 { 0, 0, 0, 0 }, /* SOUND_MIXER_SPEAKER */
888 { 0, 4, 6, 31 }, /* SOUND_MIXER_LINE */
889 { 2, 6, 4, 3 }, /* SOUND_MIXER_MIC */
890 { 0, 0, 0, 0 }, /* SOUND_MIXER_CD */
891 { 0, 0, 0, 0 }, /* SOUND_MIXER_IMIX */
892 { 0, 0, 0, 0 }, /* SOUND_MIXER_ALTPCM */
894 { 3, 7, 0, 10 }, /* SOUND_MIXER_RECLEV */
895 { 0, 0, 0, 0 }, /* SOUND_MIXER_IGAIN */
897 { 0, 0, 0, 0 }, /* SOUND_MIXER_RECLEV */
898 { 3, 7, 0, 7 }, /* SOUND_MIXER_IGAIN */
900 { 0, 0, 0, 0 }, /* SOUND_MIXER_OGAIN */
901 { 0, 4, 1, 31 }, /* SOUND_MIXER_LINE1 */
902 { 1, 5, 6, 31 }, /* SOUND_MIXER_LINE2 */
903 { 0, 0, 0, 0 }, /* SOUND_MIXER_LINE3 */
904 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL1 */
905 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL2 */
906 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL3 */
907 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEIN */
908 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEOUT */
909 { 0, 0, 0, 0 }, /* SOUND_MIXER_VIDEO */
910 { 0, 0, 0, 0 }, /* SOUND_MIXER_RADIO */
911 { 0, 0, 0, 0 } /* SOUND_MIXER_MONITOR */
915 waveartist_mixer_update(wavnc_info
*devc
, int whichDev
)
917 unsigned int lev_left
, lev_right
;
919 lev_left
= devc
->levels
[whichDev
] & 0xff;
920 lev_right
= devc
->levels
[whichDev
] >> 8;
927 #define SCALE(lev,max) ((lev) * (max) / 100)
929 if (machine_is_netwinder() && whichDev
== SOUND_MIXER_PHONEOUT
)
930 whichDev
= SOUND_MIXER_VOLUME
;
932 if (mix_devs
[whichDev
].reg_l
|| mix_devs
[whichDev
].reg_r
) {
933 const struct mix_ent
*mix
= mix_devs
+ whichDev
;
934 unsigned int mask
, left
, right
;
936 mask
= mix
->max
<< mix
->shift
;
937 lev_left
= SCALE(lev_left
, mix
->max
) << mix
->shift
;
938 lev_right
= SCALE(lev_right
, mix
->max
) << mix
->shift
;
940 /* read left setting */
941 left
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
|
944 /* read right setting */
945 right
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
|
948 left
= (left
& ~mask
) | (lev_left
& mask
);
949 right
= (right
& ~mask
) | (lev_right
& mask
);
951 /* write left,right back */
952 waveartist_cmd3(devc
, WACMD_SET_MIXER
, left
, right
);
955 case SOUND_MIXER_PCM
:
956 waveartist_cmd3(devc
, WACMD_SET_LEVEL
,
957 SCALE(lev_left
, 32767),
958 SCALE(lev_right
, 32767));
961 case SOUND_MIXER_SYNTH
:
962 waveartist_cmd3(devc
, 0x0100 | WACMD_SET_LEVEL
,
963 SCALE(lev_left
, 32767),
964 SCALE(lev_right
, 32767));
971 * Set the ADC MUX to the specified values. We do NOT do any
972 * checking of the values passed, since we assume that the
973 * relevant *_select_input function has done that for us.
976 waveartist_set_adc_mux(wavnc_info
*devc
, char left_dev
, char right_dev
)
978 unsigned int reg_08
, reg_09
;
980 reg_08
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
| 0x0800);
981 reg_09
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
| 0x0900);
983 reg_08
= (reg_08
& ~0x3f) | right_dev
<< 3 | left_dev
;
985 waveartist_cmd3(devc
, WACMD_SET_MIXER
, reg_08
, reg_09
);
989 * Decode a recording mask into a mixer selection as follows:
991 * OSS Source WA Source Actual source
992 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
993 * SOUND_MASK_LINE Line Line in
994 * SOUND_MASK_LINE1 Aux 1 Aux 1 in
995 * SOUND_MASK_LINE2 Aux 2 Aux 2 in
996 * SOUND_MASK_MIC Mic Microphone
999 waveartist_select_input(wavnc_info
*devc
, unsigned int recmask
,
1000 unsigned char *dev_l
, unsigned char *dev_r
)
1002 unsigned int recdev
= ADC_MUX_NONE
;
1004 if (recmask
& SOUND_MASK_IMIX
) {
1005 recmask
= SOUND_MASK_IMIX
;
1006 recdev
= ADC_MUX_MIXER
;
1007 } else if (recmask
& SOUND_MASK_LINE2
) {
1008 recmask
= SOUND_MASK_LINE2
;
1009 recdev
= ADC_MUX_AUX2
;
1010 } else if (recmask
& SOUND_MASK_LINE1
) {
1011 recmask
= SOUND_MASK_LINE1
;
1012 recdev
= ADC_MUX_AUX1
;
1013 } else if (recmask
& SOUND_MASK_LINE
) {
1014 recmask
= SOUND_MASK_LINE
;
1015 recdev
= ADC_MUX_LINE
;
1016 } else if (recmask
& SOUND_MASK_MIC
) {
1017 recmask
= SOUND_MASK_MIC
;
1018 recdev
= ADC_MUX_MIC
;
1021 *dev_l
= *dev_r
= recdev
;
1027 waveartist_decode_mixer(wavnc_info
*devc
, int dev
, unsigned char lev_l
,
1028 unsigned char lev_r
)
1031 case SOUND_MIXER_VOLUME
:
1032 case SOUND_MIXER_SYNTH
:
1033 case SOUND_MIXER_PCM
:
1034 case SOUND_MIXER_LINE
:
1035 case SOUND_MIXER_MIC
:
1036 case SOUND_MIXER_IGAIN
:
1037 case SOUND_MIXER_LINE1
:
1038 case SOUND_MIXER_LINE2
:
1039 devc
->levels
[dev
] = lev_l
| lev_r
<< 8;
1042 case SOUND_MIXER_IMIX
:
1053 static int waveartist_get_mixer(wavnc_info
*devc
, int dev
)
1055 return devc
->levels
[dev
];
1058 static const struct waveartist_mixer_info waveartist_mixer
= {
1059 .supported_devs
= SUPPORTED_MIXER_DEVICES
| SOUND_MASK_IGAIN
,
1060 .recording_devs
= SOUND_MASK_LINE
| SOUND_MASK_MIC
|
1061 SOUND_MASK_LINE1
| SOUND_MASK_LINE2
|
1063 .stereo_devs
= (SUPPORTED_MIXER_DEVICES
| SOUND_MASK_IGAIN
) & ~
1064 (SOUND_MASK_SPEAKER
| SOUND_MASK_IMIX
),
1065 .select_input
= waveartist_select_input
,
1066 .decode_mixer
= waveartist_decode_mixer
,
1067 .get_mixer
= waveartist_get_mixer
,
1071 waveartist_set_recmask(wavnc_info
*devc
, unsigned int recmask
)
1073 unsigned char dev_l
, dev_r
;
1075 recmask
&= devc
->mix
->recording_devs
;
1078 * If more than one recording device selected,
1079 * disable the device that is currently in use.
1081 if (hweight32(recmask
) > 1)
1082 recmask
&= ~devc
->recmask
;
1085 * Translate the recording device mask into
1086 * the ADC multiplexer settings.
1088 devc
->recmask
= devc
->mix
->select_input(devc
, recmask
,
1091 waveartist_set_adc_mux(devc
, dev_l
, dev_r
);
1095 waveartist_set_mixer(wavnc_info
*devc
, int dev
, unsigned int level
)
1097 unsigned int lev_left
= level
& 0x00ff;
1098 unsigned int lev_right
= (level
& 0xff00) >> 8;
1102 if (lev_right
> 100)
1106 * Mono devices have their right volume forced to their
1107 * left volume. (from ALSA driver OSS emulation).
1109 if (!(devc
->mix
->stereo_devs
& (1 << dev
)))
1110 lev_right
= lev_left
;
1112 dev
= devc
->mix
->decode_mixer(devc
, dev
, lev_left
, lev_right
);
1115 waveartist_mixer_update(devc
, dev
);
1117 return dev
< 0 ? dev
: 0;
1121 waveartist_mixer_ioctl(int dev
, unsigned int cmd
, void __user
* arg
)
1123 wavnc_info
*devc
= (wavnc_info
*)audio_devs
[dev
]->devc
;
1124 int ret
= 0, val
, nr
;
1127 * All SOUND_MIXER_* ioctls use type 'M'
1129 if (((cmd
>> 8) & 255) != 'M')
1130 return -ENOIOCTLCMD
;
1132 #ifdef CONFIG_ARCH_NETWINDER
1133 if (machine_is_netwinder()) {
1134 ret
= vnc_private_ioctl(dev
, cmd
, arg
);
1135 if (ret
!= -ENOIOCTLCMD
)
1144 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
) {
1145 if (get_user(val
, (int __user
*)arg
))
1149 case SOUND_MIXER_RECSRC
:
1150 waveartist_set_recmask(devc
, val
);
1155 if (nr
< SOUND_MIXER_NRDEVICES
&&
1156 devc
->mix
->supported_devs
& (1 << nr
))
1157 ret
= waveartist_set_mixer(devc
, nr
, val
);
1161 if (ret
== 0 && _SIOC_DIR(cmd
) & _SIOC_READ
) {
1165 case SOUND_MIXER_RECSRC
:
1166 ret
= devc
->recmask
;
1169 case SOUND_MIXER_DEVMASK
:
1170 ret
= devc
->mix
->supported_devs
;
1173 case SOUND_MIXER_STEREODEVS
:
1174 ret
= devc
->mix
->stereo_devs
;
1177 case SOUND_MIXER_RECMASK
:
1178 ret
= devc
->mix
->recording_devs
;
1181 case SOUND_MIXER_CAPS
:
1182 ret
= SOUND_CAP_EXCL_INPUT
;
1186 if (nr
< SOUND_MIXER_NRDEVICES
)
1187 ret
= devc
->mix
->get_mixer(devc
, nr
);
1192 ret
= put_user(ret
, (int __user
*)arg
) ? -EFAULT
: 0;
1198 static struct mixer_operations waveartist_mixer_operations
=
1200 .owner
= THIS_MODULE
,
1202 .name
= "WaveArtist",
1203 .ioctl
= waveartist_mixer_ioctl
1207 waveartist_mixer_reset(wavnc_info
*devc
)
1211 if (debug_flg
& DEBUG_MIXER
)
1212 printk("%s: mixer_reset\n", devc
->hw
.name
);
1217 waveartist_cmd1(devc
, WACMD_RST_MIXER
);
1220 * set input for ADC to come from 'quiet'
1221 * turn on default modes
1223 waveartist_cmd3(devc
, WACMD_SET_MIXER
, 0x9800, 0xa836);
1226 * set mixer input select to none, RX filter gains 0 dB
1228 waveartist_cmd3(devc
, WACMD_SET_MIXER
, 0x4c00, 0x8c00);
1231 * set bit 0 reg 2 to 1 - unmute MonoOut
1233 waveartist_cmd3(devc
, WACMD_SET_MIXER
, 0x2801, 0x6800);
1235 /* set default input device = internal mic
1236 * current recording device = none
1238 waveartist_set_recmask(devc
, 0);
1240 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
1241 waveartist_mixer_update(devc
, i
);
1244 static int __init
waveartist_init(wavnc_info
*devc
)
1246 wavnc_port_info
*portc
;
1247 char rev
[3], dev_name
[64];
1250 if (waveartist_reset(devc
))
1253 sprintf(dev_name
, "%s (%s", devc
->hw
.name
, devc
->chip_name
);
1255 if (waveartist_getrev(devc
, rev
)) {
1256 strcat(dev_name
, " rev. ");
1257 strcat(dev_name
, rev
);
1259 strcat(dev_name
, ")");
1261 conf_printf2(dev_name
, devc
->hw
.io_base
, devc
->hw
.irq
,
1262 devc
->hw
.dma
, devc
->hw
.dma2
);
1264 portc
= kzalloc(sizeof(wavnc_port_info
), GFP_KERNEL
);
1268 my_dev
= sound_install_audiodrv(AUDIO_DRIVER_VERSION
, dev_name
,
1269 &waveartist_audio_driver
, sizeof(struct audio_driver
),
1270 devc
->audio_flags
, AFMT_U8
| AFMT_S16_LE
| AFMT_S8
,
1271 devc
, devc
->hw
.dma
, devc
->hw
.dma2
);
1276 audio_devs
[my_dev
]->portc
= portc
;
1278 waveartist_mixer_reset(devc
);
1281 * clear any pending interrupt
1283 waveartist_iack(devc
);
1285 if (request_irq(devc
->hw
.irq
, waveartist_intr
, 0, devc
->hw
.name
, devc
) < 0) {
1286 printk(KERN_ERR
"%s: IRQ %d in use\n",
1287 devc
->hw
.name
, devc
->hw
.irq
);
1291 if (sound_alloc_dma(devc
->hw
.dma
, devc
->hw
.name
)) {
1292 printk(KERN_ERR
"%s: Can't allocate DMA%d\n",
1293 devc
->hw
.name
, devc
->hw
.dma
);
1297 if (devc
->hw
.dma
!= devc
->hw
.dma2
&& devc
->hw
.dma2
!= NO_DMA
)
1298 if (sound_alloc_dma(devc
->hw
.dma2
, devc
->hw
.name
)) {
1299 printk(KERN_ERR
"%s: can't allocate DMA%d\n",
1300 devc
->hw
.name
, devc
->hw
.dma2
);
1304 waveartist_set_ctlr(&devc
->hw
, 0, DMA1_IE
| DMA0_IE
);
1306 audio_devs
[my_dev
]->mixer_dev
=
1307 sound_install_mixer(MIXER_DRIVER_VERSION
,
1309 &waveartist_mixer_operations
,
1310 sizeof(struct mixer_operations
),
1316 sound_free_dma(devc
->hw
.dma
);
1319 free_irq(devc
->hw
.irq
, devc
);
1322 sound_unload_audiodev(my_dev
);
1331 static int __init
probe_waveartist(struct address_info
*hw_config
)
1333 wavnc_info
*devc
= &adev_info
[nr_waveartist_devs
];
1335 if (nr_waveartist_devs
>= MAX_AUDIO_DEV
) {
1336 printk(KERN_WARNING
"waveartist: too many audio devices\n");
1340 if (!request_region(hw_config
->io_base
, 15, hw_config
->name
)) {
1341 printk(KERN_WARNING
"WaveArtist: I/O port conflict\n");
1345 if (hw_config
->irq
> 15 || hw_config
->irq
< 0) {
1346 release_region(hw_config
->io_base
, 15);
1347 printk(KERN_WARNING
"WaveArtist: Bad IRQ %d\n",
1352 if (hw_config
->dma
!= 3) {
1353 release_region(hw_config
->io_base
, 15);
1354 printk(KERN_WARNING
"WaveArtist: Bad DMA %d\n",
1359 hw_config
->name
= "WaveArtist";
1360 devc
->hw
= *hw_config
;
1361 devc
->open_mode
= 0;
1362 devc
->chip_name
= "RWA-010";
1368 attach_waveartist(struct address_info
*hw
, const struct waveartist_mixer_info
*mix
)
1370 wavnc_info
*devc
= &adev_info
[nr_waveartist_devs
];
1373 * NOTE! If irq < 0, there is another driver which has allocated the
1374 * IRQ so that this driver doesn't need to allocate/deallocate it.
1375 * The actually used IRQ is ABS(irq).
1378 devc
->hw
.irq
= (hw
->irq
> 0) ? hw
->irq
: 0;
1379 devc
->open_mode
= 0;
1380 devc
->playback_dev
= 0;
1381 devc
->record_dev
= 0;
1382 devc
->audio_flags
= DMA_AUTOMODE
;
1383 devc
->levels
= levels
;
1385 if (hw
->dma
!= hw
->dma2
&& hw
->dma2
!= NO_DMA
)
1386 devc
->audio_flags
|= DMA_DUPLEX
;
1389 devc
->dev_no
= waveartist_init(devc
);
1391 if (devc
->dev_no
< 0)
1392 release_region(hw
->io_base
, 15);
1394 #ifdef CONFIG_ARCH_NETWINDER
1395 if (machine_is_netwinder()) {
1396 init_timer(&vnc_timer
);
1397 vnc_timer
.function
= vnc_slider_tick
;
1398 vnc_timer
.expires
= jiffies
;
1399 vnc_timer
.data
= nr_waveartist_devs
;
1400 add_timer(&vnc_timer
);
1402 vnc_configure_mixer(devc
, 0);
1404 devc
->no_autoselect
= 1;
1407 nr_waveartist_devs
+= 1;
1411 static void __exit
unload_waveartist(struct address_info
*hw
)
1413 wavnc_info
*devc
= NULL
;
1416 for (i
= 0; i
< nr_waveartist_devs
; i
++)
1417 if (hw
->io_base
== adev_info
[i
].hw
.io_base
) {
1418 devc
= adev_info
+ i
;
1425 #ifdef CONFIG_ARCH_NETWINDER
1426 if (machine_is_netwinder())
1427 del_timer(&vnc_timer
);
1430 release_region(devc
->hw
.io_base
, 15);
1432 waveartist_set_ctlr(&devc
->hw
, DMA1_IE
|DMA0_IE
, 0);
1434 if (devc
->hw
.irq
>= 0)
1435 free_irq(devc
->hw
.irq
, devc
);
1437 sound_free_dma(devc
->hw
.dma
);
1439 if (devc
->hw
.dma
!= devc
->hw
.dma2
&&
1440 devc
->hw
.dma2
!= NO_DMA
)
1441 sound_free_dma(devc
->hw
.dma2
);
1443 mixer
= audio_devs
[devc
->dev_no
]->mixer_dev
;
1446 sound_unload_mixerdev(mixer
);
1448 if (devc
->dev_no
>= 0)
1449 sound_unload_audiodev(devc
->dev_no
);
1451 nr_waveartist_devs
-= 1;
1453 for (; i
< nr_waveartist_devs
; i
++)
1454 adev_info
[i
] = adev_info
[i
+ 1];
1456 printk(KERN_WARNING
"waveartist: can't find device "
1460 #ifdef CONFIG_ARCH_NETWINDER
1463 * Rebel.com Netwinder specifics...
1466 #include <asm/hardware/dec21285.h>
1468 #define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
1470 #define MIXER_PRIVATE3_RESET 0x53570000
1471 #define MIXER_PRIVATE3_READ 0x53570001
1472 #define MIXER_PRIVATE3_WRITE 0x53570002
1474 #define VNC_MUTE_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
1475 #define VNC_MUTE_LINE_OUT 0x10
1476 #define VNC_PHONE_DETECT 0x20
1477 #define VNC_HANDSET_DETECT 0x40
1478 #define VNC_DISABLE_AUTOSWITCH 0x80
1481 vnc_mute_spkr(wavnc_info
*devc
)
1483 unsigned long flags
;
1485 raw_spin_lock_irqsave(&nw_gpio_lock
, flags
);
1486 nw_cpld_modify(CPLD_UNMUTE
, devc
->spkr_mute_state
? 0 : CPLD_UNMUTE
);
1487 raw_spin_unlock_irqrestore(&nw_gpio_lock
, flags
);
1491 vnc_mute_lout(wavnc_info
*devc
)
1493 unsigned int left
, right
;
1495 left
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
);
1496 right
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
| 0x400);
1498 if (devc
->line_mute_state
) {
1505 waveartist_cmd3(devc
, WACMD_SET_MIXER
, left
, right
);
1510 vnc_volume_slider(wavnc_info
*devc
)
1512 static signed int old_slider_volume
;
1513 unsigned long flags
;
1514 signed int volume
= 255;
1516 *CSR_TIMER1_LOAD
= 0x00ffffff;
1518 spin_lock_irqsave(&waveartist_lock
, flags
);
1521 *CSR_TIMER1_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_DIV1
;
1523 while (volume
&& (inb(0x201) & 0x01))
1526 *CSR_TIMER1_CNTL
= 0;
1528 spin_unlock_irqrestore(&waveartist_lock
,flags
);
1530 volume
= 0x00ffffff - *CSR_TIMER1_VALUE
;
1534 volume
= 150 - (volume
>> 5);
1536 volume
= (volume
>> 6) - 25;
1546 * slider quite often reads +-8, so debounce this random noise
1548 if (abs(volume
- old_slider_volume
) > 7) {
1549 old_slider_volume
= volume
;
1551 if (debug_flg
& DEBUG_MIXER
)
1552 printk(KERN_DEBUG
"Slider volume: %d.\n", volume
);
1555 return old_slider_volume
;
1559 * Decode a recording mask into a mixer selection on the NetWinder
1562 * OSS Source WA Source Actual source
1563 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
1564 * SOUND_MASK_LINE Line Line in
1565 * SOUND_MASK_LINE1 Left Mic Handset
1566 * SOUND_MASK_PHONEIN Left Aux Telephone microphone
1567 * SOUND_MASK_MIC Right Mic Builtin microphone
1570 netwinder_select_input(wavnc_info
*devc
, unsigned int recmask
,
1571 unsigned char *dev_l
, unsigned char *dev_r
)
1573 unsigned int recdev_l
= ADC_MUX_NONE
, recdev_r
= ADC_MUX_NONE
;
1575 if (recmask
& SOUND_MASK_IMIX
) {
1576 recmask
= SOUND_MASK_IMIX
;
1577 recdev_l
= ADC_MUX_MIXER
;
1578 recdev_r
= ADC_MUX_MIXER
;
1579 } else if (recmask
& SOUND_MASK_LINE
) {
1580 recmask
= SOUND_MASK_LINE
;
1581 recdev_l
= ADC_MUX_LINE
;
1582 recdev_r
= ADC_MUX_LINE
;
1583 } else if (recmask
& SOUND_MASK_LINE1
) {
1584 recmask
= SOUND_MASK_LINE1
;
1585 waveartist_cmd1(devc
, WACMD_SET_MONO
); /* left */
1586 recdev_l
= ADC_MUX_MIC
;
1587 recdev_r
= ADC_MUX_NONE
;
1588 } else if (recmask
& SOUND_MASK_PHONEIN
) {
1589 recmask
= SOUND_MASK_PHONEIN
;
1590 waveartist_cmd1(devc
, WACMD_SET_MONO
); /* left */
1591 recdev_l
= ADC_MUX_AUX1
;
1592 recdev_r
= ADC_MUX_NONE
;
1593 } else if (recmask
& SOUND_MASK_MIC
) {
1594 recmask
= SOUND_MASK_MIC
;
1595 waveartist_cmd1(devc
, WACMD_SET_MONO
| 0x100); /* right */
1596 recdev_l
= ADC_MUX_NONE
;
1597 recdev_r
= ADC_MUX_MIC
;
1607 netwinder_decode_mixer(wavnc_info
*devc
, int dev
, unsigned char lev_l
,
1608 unsigned char lev_r
)
1611 case SOUND_MIXER_VOLUME
:
1612 case SOUND_MIXER_SYNTH
:
1613 case SOUND_MIXER_PCM
:
1614 case SOUND_MIXER_LINE
:
1615 case SOUND_MIXER_IGAIN
:
1616 devc
->levels
[dev
] = lev_l
| lev_r
<< 8;
1619 case SOUND_MIXER_MIC
: /* right mic only */
1620 devc
->levels
[SOUND_MIXER_MIC
] &= 0xff;
1621 devc
->levels
[SOUND_MIXER_MIC
] |= lev_l
<< 8;
1624 case SOUND_MIXER_LINE1
: /* left mic only */
1625 devc
->levels
[SOUND_MIXER_MIC
] &= 0xff00;
1626 devc
->levels
[SOUND_MIXER_MIC
] |= lev_l
;
1627 dev
= SOUND_MIXER_MIC
;
1630 case SOUND_MIXER_PHONEIN
: /* left aux only */
1631 devc
->levels
[SOUND_MIXER_LINE1
] = lev_l
;
1632 dev
= SOUND_MIXER_LINE1
;
1635 case SOUND_MIXER_IMIX
:
1636 case SOUND_MIXER_PHONEOUT
:
1646 static int netwinder_get_mixer(wavnc_info
*devc
, int dev
)
1651 case SOUND_MIXER_VOLUME
:
1652 case SOUND_MIXER_SYNTH
:
1653 case SOUND_MIXER_PCM
:
1654 case SOUND_MIXER_LINE
:
1655 case SOUND_MIXER_IGAIN
:
1656 levels
= devc
->levels
[dev
];
1659 case SOUND_MIXER_MIC
: /* builtin mic: right mic only */
1660 levels
= devc
->levels
[SOUND_MIXER_MIC
] >> 8;
1661 levels
|= levels
<< 8;
1664 case SOUND_MIXER_LINE1
: /* handset mic: left mic only */
1665 levels
= devc
->levels
[SOUND_MIXER_MIC
] & 0xff;
1666 levels
|= levels
<< 8;
1669 case SOUND_MIXER_PHONEIN
: /* phone mic: left aux1 only */
1670 levels
= devc
->levels
[SOUND_MIXER_LINE1
] & 0xff;
1671 levels
|= levels
<< 8;
1682 * Waveartist specific mixer information.
1684 static const struct waveartist_mixer_info netwinder_mixer
= {
1685 .supported_devs
= SOUND_MASK_VOLUME
| SOUND_MASK_SYNTH
|
1686 SOUND_MASK_PCM
| SOUND_MASK_SPEAKER
|
1687 SOUND_MASK_LINE
| SOUND_MASK_MIC
|
1688 SOUND_MASK_IMIX
| SOUND_MASK_LINE1
|
1689 SOUND_MASK_PHONEIN
| SOUND_MASK_PHONEOUT
|
1692 .recording_devs
= SOUND_MASK_LINE
| SOUND_MASK_MIC
|
1693 SOUND_MASK_IMIX
| SOUND_MASK_LINE1
|
1696 .stereo_devs
= SOUND_MASK_VOLUME
| SOUND_MASK_SYNTH
|
1697 SOUND_MASK_PCM
| SOUND_MASK_LINE
|
1698 SOUND_MASK_IMIX
| SOUND_MASK_IGAIN
,
1700 .select_input
= netwinder_select_input
,
1701 .decode_mixer
= netwinder_decode_mixer
,
1702 .get_mixer
= netwinder_get_mixer
,
1706 vnc_configure_mixer(wavnc_info
*devc
, unsigned int recmask
)
1708 if (!devc
->no_autoselect
) {
1709 if (devc
->handset_detect
) {
1710 recmask
= SOUND_MASK_LINE1
;
1711 devc
->spkr_mute_state
= devc
->line_mute_state
= 1;
1712 } else if (devc
->telephone_detect
) {
1713 recmask
= SOUND_MASK_PHONEIN
;
1714 devc
->spkr_mute_state
= devc
->line_mute_state
= 1;
1716 /* unless someone has asked for LINE-IN,
1719 if ((devc
->recmask
& SOUND_MASK_LINE
) == 0)
1720 devc
->recmask
= SOUND_MASK_MIC
;
1721 devc
->spkr_mute_state
= devc
->line_mute_state
= 0;
1723 vnc_mute_spkr(devc
);
1724 vnc_mute_lout(devc
);
1726 if (recmask
!= devc
->recmask
)
1727 waveartist_set_recmask(devc
, recmask
);
1732 vnc_slider(wavnc_info
*devc
)
1734 signed int slider_volume
;
1735 unsigned int temp
, old_hs
, old_td
;
1738 * read the "buttons" state.
1739 * Bit 4 = 0 means handset present
1740 * Bit 5 = 1 means phone offhook
1744 old_hs
= devc
->handset_detect
;
1745 old_td
= devc
->telephone_detect
;
1747 devc
->handset_detect
= !(temp
& 0x10);
1748 devc
->telephone_detect
= !!(temp
& 0x20);
1750 if (!devc
->no_autoselect
&&
1751 (old_hs
!= devc
->handset_detect
||
1752 old_td
!= devc
->telephone_detect
))
1753 vnc_configure_mixer(devc
, devc
->recmask
);
1755 slider_volume
= vnc_volume_slider(devc
);
1758 * If we're using software controlled volume, and
1759 * the slider moves by more than 20%, then we
1760 * switch back to slider controlled volume.
1762 if (abs(devc
->slider_vol
- slider_volume
) > 20)
1763 devc
->use_slider
= 1;
1766 * use only left channel
1768 temp
= levels
[SOUND_MIXER_VOLUME
] & 0xFF;
1770 if (slider_volume
!= temp
&& devc
->use_slider
) {
1771 devc
->slider_vol
= slider_volume
;
1773 waveartist_set_mixer(devc
, SOUND_MIXER_VOLUME
,
1774 slider_volume
| slider_volume
<< 8);
1783 vnc_slider_tick(unsigned long data
)
1787 if (vnc_slider(adev_info
+ data
))
1788 next_timeout
= 5; // mixer reported change
1790 next_timeout
= VNC_TIMER_PERIOD
;
1792 mod_timer(&vnc_timer
, jiffies
+ next_timeout
);
1796 vnc_private_ioctl(int dev
, unsigned int cmd
, int __user
* arg
)
1798 wavnc_info
*devc
= (wavnc_info
*)audio_devs
[dev
]->devc
;
1802 case SOUND_MIXER_PRIVATE1
:
1804 u_int prev_spkr_mute
, prev_line_mute
, prev_auto_state
;
1807 if (get_user(val
, arg
))
1810 /* check if parameter is logical */
1811 if (val
& ~(VNC_MUTE_INTERNAL_SPKR
|
1813 VNC_DISABLE_AUTOSWITCH
))
1816 prev_auto_state
= devc
->no_autoselect
;
1817 prev_spkr_mute
= devc
->spkr_mute_state
;
1818 prev_line_mute
= devc
->line_mute_state
;
1820 devc
->no_autoselect
= (val
& VNC_DISABLE_AUTOSWITCH
) ? 1 : 0;
1821 devc
->spkr_mute_state
= (val
& VNC_MUTE_INTERNAL_SPKR
) ? 1 : 0;
1822 devc
->line_mute_state
= (val
& VNC_MUTE_LINE_OUT
) ? 1 : 0;
1824 if (prev_spkr_mute
!= devc
->spkr_mute_state
)
1825 vnc_mute_spkr(devc
);
1827 if (prev_line_mute
!= devc
->line_mute_state
)
1828 vnc_mute_lout(devc
);
1830 if (prev_auto_state
!= devc
->no_autoselect
)
1831 vnc_configure_mixer(devc
, devc
->recmask
);
1836 case SOUND_MIXER_PRIVATE2
:
1837 if (get_user(val
, arg
))
1841 #define VNC_SOUND_PAUSE 0x53 //to pause the DSP
1842 #define VNC_SOUND_RESUME 0x57 //to unpause the DSP
1843 case VNC_SOUND_PAUSE
:
1844 waveartist_cmd1(devc
, 0x16);
1847 case VNC_SOUND_RESUME
:
1848 waveartist_cmd1(devc
, 0x18);
1856 /* private ioctl to allow bulk access to waveartist */
1857 case SOUND_MIXER_PRIVATE3
:
1859 unsigned long flags
;
1860 int mixer_reg
[15], i
, val
;
1862 if (get_user(val
, arg
))
1864 if (copy_from_user(mixer_reg
, (void *)val
, sizeof(mixer_reg
)))
1867 switch (mixer_reg
[14]) {
1868 case MIXER_PRIVATE3_RESET
:
1869 waveartist_mixer_reset(devc
);
1872 case MIXER_PRIVATE3_WRITE
:
1873 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[0], mixer_reg
[4]);
1874 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[1], mixer_reg
[5]);
1875 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[2], mixer_reg
[6]);
1876 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[3], mixer_reg
[7]);
1877 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[8], mixer_reg
[9]);
1879 waveartist_cmd3(devc
, WACMD_SET_LEVEL
, mixer_reg
[10], mixer_reg
[11]);
1880 waveartist_cmd3(devc
, WACMD_SET_LEVEL
, mixer_reg
[12], mixer_reg
[13]);
1883 case MIXER_PRIVATE3_READ
:
1884 spin_lock_irqsave(&waveartist_lock
, flags
);
1886 for (i
= 0x30; i
< 14 << 8; i
+= 1 << 8)
1887 waveartist_cmd(devc
, 1, &i
, 1, mixer_reg
+ (i
>> 8));
1889 spin_unlock_irqrestore(&waveartist_lock
, flags
);
1891 if (copy_to_user((void *)val
, mixer_reg
, sizeof(mixer_reg
)))
1901 /* read back the state from PRIVATE1 */
1902 case SOUND_MIXER_PRIVATE4
:
1903 val
= (devc
->spkr_mute_state
? VNC_MUTE_INTERNAL_SPKR
: 0) |
1904 (devc
->line_mute_state
? VNC_MUTE_LINE_OUT
: 0) |
1905 (devc
->handset_detect
? VNC_HANDSET_DETECT
: 0) |
1906 (devc
->telephone_detect
? VNC_PHONE_DETECT
: 0) |
1907 (devc
->no_autoselect
? VNC_DISABLE_AUTOSWITCH
: 0);
1909 return put_user(val
, arg
) ? -EFAULT
: 0;
1912 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
) {
1914 * special case for master volume: if we
1915 * received this call - switch from hw
1916 * volume control to a software volume
1917 * control, till the hw volume is modified
1918 * to signal that user wants to be back in
1921 if ((cmd
& 0xff) == SOUND_MIXER_VOLUME
)
1922 devc
->use_slider
= 0;
1924 /* speaker output */
1925 if ((cmd
& 0xff) == SOUND_MIXER_SPEAKER
) {
1926 unsigned int val
, l
, r
;
1928 if (get_user(val
, arg
))
1932 r
= (val
& 0x7f00) >> 8;
1934 devc
->levels
[SOUND_MIXER_SPEAKER
] = val
| (val
<< 8);
1935 devc
->spkr_mute_state
= (val
<= 50);
1936 vnc_mute_spkr(devc
);
1941 return -ENOIOCTLCMD
;
1946 static struct address_info cfg
;
1948 static int attached
;
1950 static int __initdata io
= 0;
1951 static int __initdata irq
= 0;
1952 static int __initdata dma
= 0;
1953 static int __initdata dma2
= 0;
1956 static int __init
init_waveartist(void)
1958 const struct waveartist_mixer_info
*mix
;
1960 if (!io
&& machine_is_netwinder()) {
1962 * The NetWinder WaveArtist is at a fixed address.
1963 * If the user does not supply an address, use the
1964 * well-known parameters.
1972 mix
= &waveartist_mixer
;
1973 #ifdef CONFIG_ARCH_NETWINDER
1974 if (machine_is_netwinder())
1975 mix
= &netwinder_mixer
;
1983 if (!probe_waveartist(&cfg
))
1986 attach_waveartist(&cfg
, mix
);
1992 static void __exit
cleanup_waveartist(void)
1995 unload_waveartist(&cfg
);
1998 module_init(init_waveartist
);
1999 module_exit(cleanup_waveartist
);
2002 static int __init
setup_waveartist(char *str
)
2004 /* io, irq, dma, dma2 */
2007 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
2016 __setup("waveartist=", setup_waveartist
);
2019 MODULE_DESCRIPTION("Rockwell WaveArtist RWA-010 sound driver");
2020 module_param(io
, int, 0); /* IO base */
2021 module_param(irq
, int, 0); /* IRQ */
2022 module_param(dma
, int, 0); /* DMA */
2023 module_param(dma2
, int, 0); /* DMA2 */
2024 MODULE_LICENSE("GPL");