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
)(struct wavnc_info
*, unsigned int,
133 unsigned char *, unsigned char *);
134 int (*decode_mixer
)(struct wavnc_info
*, int,
135 unsigned char, unsigned char);
136 int (*get_mixer
)(struct wavnc_info
*, int);
139 struct wavnc_port_info
{
146 static int nr_waveartist_devs
;
147 static struct 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(struct wavnc_info
*devc
,
155 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(struct 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(struct 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(struct 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(struct 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(struct 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(struct 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(struct 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(struct 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
)
375 struct wavnc_info
*devc
;
376 struct wavnc_port_info
*portc
;
379 if (dev
< 0 || dev
>= num_audiodevs
)
382 devc
= (struct wavnc_info
*) audio_devs
[dev
]->devc
;
383 portc
= (struct 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 struct wavnc_info
*devc
= (struct wavnc_info
*)
409 audio_devs
[dev
]->devc
;
410 struct wavnc_port_info
*portc
= (struct wavnc_port_info
*)
411 audio_devs
[dev
]->portc
;
414 spin_lock_irqsave(&waveartist_lock
, flags
);
416 waveartist_halt(dev
);
418 devc
->audio_mode
= 0;
419 devc
->open_mode
&= ~portc
->open_mode
;
420 portc
->open_mode
= 0;
422 spin_unlock_irqrestore(&waveartist_lock
, flags
);
426 waveartist_output_block(int dev
, unsigned long buf
, int __count
, int intrflag
)
428 struct wavnc_port_info
*portc
= (struct wavnc_port_info
*)
429 audio_devs
[dev
]->portc
;
430 struct wavnc_info
*devc
= (struct wavnc_info
*)
431 audio_devs
[dev
]->devc
;
433 unsigned int count
= __count
;
435 if (debug_flg
& DEBUG_OUT
)
436 printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
441 if (portc
->audio_format
& (AFMT_S16_LE
| AFMT_S16_BE
))
444 if (portc
->channels
> 1)
449 if (devc
->audio_mode
& PCM_ENABLE_OUTPUT
&&
450 audio_devs
[dev
]->flags
& DMA_AUTOMODE
&&
452 count
== devc
->xfer_count
) {
453 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
455 * Auto DMA mode on. No need to react
459 spin_lock_irqsave(&waveartist_lock
, flags
);
464 waveartist_cmd2(devc
, WACMD_OUTPUTSIZE
, count
);
466 devc
->xfer_count
= count
;
467 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
469 spin_unlock_irqrestore(&waveartist_lock
, flags
);
473 waveartist_start_input(int dev
, unsigned long buf
, int __count
, int intrflag
)
475 struct wavnc_port_info
*portc
= (struct wavnc_port_info
*)
476 audio_devs
[dev
]->portc
;
477 struct wavnc_info
*devc
= (struct wavnc_info
*)
478 audio_devs
[dev
]->devc
;
480 unsigned int count
= __count
;
482 if (debug_flg
& DEBUG_IN
)
483 printk("waveartist: start input, buf=0x%lx, count=0x%x...\n",
486 if (portc
->audio_format
& (AFMT_S16_LE
| AFMT_S16_BE
)) /* 16 bit data */
489 if (portc
->channels
> 1)
494 if (devc
->audio_mode
& PCM_ENABLE_INPUT
&&
495 audio_devs
[dev
]->flags
& DMA_AUTOMODE
&&
497 count
== devc
->xfer_count
) {
498 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
500 * Auto DMA mode on. No need to react
504 spin_lock_irqsave(&waveartist_lock
, flags
);
509 waveartist_cmd2(devc
, WACMD_INPUTSIZE
, count
);
511 devc
->xfer_count
= count
;
512 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
514 spin_unlock_irqrestore(&waveartist_lock
, flags
);
518 waveartist_ioctl(int dev
, unsigned int cmd
, void __user
* arg
)
524 waveartist_get_speed(struct wavnc_port_info
*portc
)
529 * program the speed, channels, bits
531 if (portc
->speed
== 8000)
533 else if (portc
->speed
== 11025)
535 else if (portc
->speed
== 22050)
537 else if (portc
->speed
== 44100)
541 * non-standard - just calculate
543 speed
= portc
->speed
<< 16;
545 speed
= (speed
/ 44100) & 65535;
552 waveartist_get_bits(struct wavnc_port_info
*portc
)
556 if (portc
->audio_format
== AFMT_S16_LE
)
558 else if (portc
->audio_format
== AFMT_S8
)
561 bits
= 2; //default AFMT_U8
567 waveartist_prepare_for_input(int dev
, int bsize
, int bcount
)
570 struct wavnc_info
*devc
= (struct wavnc_info
*)
571 audio_devs
[dev
]->devc
;
572 struct wavnc_port_info
*portc
= (struct wavnc_port_info
*)
573 audio_devs
[dev
]->portc
;
574 unsigned int speed
, bits
;
576 if (devc
->audio_mode
)
579 speed
= waveartist_get_speed(portc
);
580 bits
= waveartist_get_bits(portc
);
582 spin_lock_irqsave(&waveartist_lock
, flags
);
584 if (waveartist_cmd2(devc
, WACMD_INPUTFORMAT
, bits
))
585 printk(KERN_WARNING
"waveartist: error setting the "
586 "record format to %d\n", portc
->audio_format
);
588 if (waveartist_cmd2(devc
, WACMD_INPUTCHANNELS
, portc
->channels
))
589 printk(KERN_WARNING
"waveartist: error setting record "
590 "to %d channels\n", portc
->channels
);
593 * write cmd SetSampleSpeedTimeConstant
595 if (waveartist_cmd2(devc
, WACMD_INPUTSPEED
, speed
))
596 printk(KERN_WARNING
"waveartist: error setting the record "
597 "speed to %dHz.\n", portc
->speed
);
599 if (waveartist_cmd2(devc
, WACMD_INPUTDMA
, 1))
600 printk(KERN_WARNING
"waveartist: error setting the record "
601 "data path to 0x%X\n", 1);
603 if (waveartist_cmd2(devc
, WACMD_INPUTFORMAT
, bits
))
604 printk(KERN_WARNING
"waveartist: error setting the record "
605 "format to %d\n", portc
->audio_format
);
607 devc
->xfer_count
= 0;
608 spin_unlock_irqrestore(&waveartist_lock
, flags
);
609 waveartist_halt_input(dev
);
611 if (debug_flg
& DEBUG_INTR
) {
612 printk("WA CTLR reg: 0x%02X.\n",
613 inb(devc
->hw
.io_base
+ CTLR
));
614 printk("WA STAT reg: 0x%02X.\n",
615 inb(devc
->hw
.io_base
+ STATR
));
616 printk("WA IRQS reg: 0x%02X.\n",
617 inb(devc
->hw
.io_base
+ IRQSTAT
));
624 waveartist_prepare_for_output(int dev
, int bsize
, int bcount
)
627 struct wavnc_info
*devc
= (struct wavnc_info
*)
628 audio_devs
[dev
]->devc
;
629 struct wavnc_port_info
*portc
= (struct wavnc_port_info
*)
630 audio_devs
[dev
]->portc
;
631 unsigned int speed
, bits
;
634 * program the speed, channels, bits
636 speed
= waveartist_get_speed(portc
);
637 bits
= waveartist_get_bits(portc
);
639 spin_lock_irqsave(&waveartist_lock
, flags
);
641 if (waveartist_cmd2(devc
, WACMD_OUTPUTSPEED
, speed
) &&
642 waveartist_cmd2(devc
, WACMD_OUTPUTSPEED
, speed
))
643 printk(KERN_WARNING
"waveartist: error setting the playback "
644 "speed to %dHz.\n", portc
->speed
);
646 if (waveartist_cmd2(devc
, WACMD_OUTPUTCHANNELS
, portc
->channels
))
647 printk(KERN_WARNING
"waveartist: error setting the playback "
648 "to %d channels\n", portc
->channels
);
650 if (waveartist_cmd2(devc
, WACMD_OUTPUTDMA
, 0))
651 printk(KERN_WARNING
"waveartist: error setting the playback "
652 "data path to 0x%X\n", 0);
654 if (waveartist_cmd2(devc
, WACMD_OUTPUTFORMAT
, bits
))
655 printk(KERN_WARNING
"waveartist: error setting the playback "
656 "format to %d\n", portc
->audio_format
);
658 devc
->xfer_count
= 0;
659 spin_unlock_irqrestore(&waveartist_lock
, flags
);
660 waveartist_halt_output(dev
);
662 if (debug_flg
& DEBUG_INTR
) {
663 printk("WA CTLR reg: 0x%02X.\n",inb(devc
->hw
.io_base
+ CTLR
));
664 printk("WA STAT reg: 0x%02X.\n",inb(devc
->hw
.io_base
+ STATR
));
665 printk("WA IRQS reg: 0x%02X.\n",inb(devc
->hw
.io_base
+ IRQSTAT
));
672 waveartist_halt(int dev
)
674 struct wavnc_port_info
*portc
= (struct wavnc_port_info
*)
675 audio_devs
[dev
]->portc
;
676 struct wavnc_info
*devc
;
678 if (portc
->open_mode
& OPEN_WRITE
)
679 waveartist_halt_output(dev
);
681 if (portc
->open_mode
& OPEN_READ
)
682 waveartist_halt_input(dev
);
684 devc
= (struct wavnc_info
*) audio_devs
[dev
]->devc
;
685 devc
->audio_mode
= 0;
689 waveartist_halt_input(int dev
)
691 struct wavnc_info
*devc
= (struct wavnc_info
*)
692 audio_devs
[dev
]->devc
;
695 spin_lock_irqsave(&waveartist_lock
, flags
);
700 waveartist_cmd1(devc
, WACMD_INPUTSTOP
);
702 devc
->audio_mode
&= ~PCM_ENABLE_INPUT
;
705 * Clear interrupt by toggling
706 * the IRQ_ACK bit in CTRL
708 if (inb(devc
->hw
.io_base
+ STATR
) & IRQ_REQ
)
709 waveartist_iack(devc
);
711 // devc->audio_mode &= ~PCM_ENABLE_INPUT;
713 spin_unlock_irqrestore(&waveartist_lock
, flags
);
717 waveartist_halt_output(int dev
)
719 struct wavnc_info
*devc
= (struct wavnc_info
*)
720 audio_devs
[dev
]->devc
;
723 spin_lock_irqsave(&waveartist_lock
, flags
);
725 waveartist_cmd1(devc
, WACMD_OUTPUTSTOP
);
727 devc
->audio_mode
&= ~PCM_ENABLE_OUTPUT
;
730 * Clear interrupt by toggling
731 * the IRQ_ACK bit in CTRL
733 if (inb(devc
->hw
.io_base
+ STATR
) & IRQ_REQ
)
734 waveartist_iack(devc
);
736 // devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
738 spin_unlock_irqrestore(&waveartist_lock
, flags
);
742 waveartist_trigger(int dev
, int state
)
744 struct wavnc_info
*devc
= (struct wavnc_info
*)
745 audio_devs
[dev
]->devc
;
746 struct wavnc_port_info
*portc
= (struct wavnc_port_info
*)
747 audio_devs
[dev
]->portc
;
750 if (debug_flg
& DEBUG_TRIGGER
) {
751 printk("wavnc: audio trigger ");
752 if (state
& PCM_ENABLE_INPUT
)
754 if (state
& PCM_ENABLE_OUTPUT
)
759 spin_lock_irqsave(&waveartist_lock
, flags
);
761 state
&= devc
->audio_mode
;
763 if (portc
->open_mode
& OPEN_READ
&&
764 state
& PCM_ENABLE_INPUT
)
766 * enable ADC Data Transfer to PC
768 waveartist_cmd1(devc
, WACMD_INPUTSTART
);
770 if (portc
->open_mode
& OPEN_WRITE
&&
771 state
& PCM_ENABLE_OUTPUT
)
773 * enable DAC data transfer from PC
775 waveartist_cmd1(devc
, WACMD_OUTPUTSTART
);
777 spin_unlock_irqrestore(&waveartist_lock
, flags
);
781 waveartist_set_speed(int dev
, int arg
)
783 struct wavnc_port_info
*portc
= (struct wavnc_port_info
*)
784 audio_devs
[dev
]->portc
;
800 waveartist_set_channels(int dev
, short arg
)
802 struct wavnc_port_info
*portc
= (struct wavnc_port_info
*)
803 audio_devs
[dev
]->portc
;
805 if (arg
!= 1 && arg
!= 2)
806 return portc
->channels
;
808 portc
->channels
= arg
;
813 waveartist_set_bits(int dev
, unsigned int arg
)
815 struct wavnc_port_info
*portc
= (struct wavnc_port_info
*)
816 audio_devs
[dev
]->portc
;
819 return portc
->audio_format
;
821 if ((arg
!= AFMT_U8
) && (arg
!= AFMT_S16_LE
) && (arg
!= AFMT_S8
))
824 portc
->audio_format
= arg
;
829 static struct audio_driver waveartist_audio_driver
= {
830 .owner
= THIS_MODULE
,
831 .open
= waveartist_open
,
832 .close
= waveartist_close
,
833 .output_block
= waveartist_output_block
,
834 .start_input
= waveartist_start_input
,
835 .ioctl
= waveartist_ioctl
,
836 .prepare_for_input
= waveartist_prepare_for_input
,
837 .prepare_for_output
= waveartist_prepare_for_output
,
838 .halt_io
= waveartist_halt
,
839 .halt_input
= waveartist_halt_input
,
840 .halt_output
= waveartist_halt_output
,
841 .trigger
= waveartist_trigger
,
842 .set_speed
= waveartist_set_speed
,
843 .set_bits
= waveartist_set_bits
,
844 .set_channels
= waveartist_set_channels
849 waveartist_intr(int irq
, void *dev_id
)
851 struct wavnc_info
*devc
= dev_id
;
852 int irqstatus
, status
;
854 spin_lock(&waveartist_lock
);
855 irqstatus
= inb(devc
->hw
.io_base
+ IRQSTAT
);
856 status
= inb(devc
->hw
.io_base
+ STATR
);
858 if (debug_flg
& DEBUG_INTR
)
859 printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
862 if (status
& IRQ_REQ
) /* Clear interrupt */
863 waveartist_iack(devc
);
865 printk(KERN_WARNING
"waveartist: unexpected interrupt\n");
867 if (irqstatus
& 0x01) {
872 if ((status
& DMA0
) && (devc
->audio_mode
& PCM_ENABLE_OUTPUT
)) {
873 DMAbuf_outputintr(devc
->playback_dev
, 1);
876 if ((status
& DMA1
) && (devc
->audio_mode
& PCM_ENABLE_INPUT
)) {
877 DMAbuf_inputintr(devc
->record_dev
);
881 printk(KERN_WARNING
"waveartist: Unknown interrupt\n");
884 // We do not use SB mode natively...
885 printk(KERN_WARNING
"waveartist: Unexpected SB interrupt...\n");
886 spin_unlock(&waveartist_lock
);
890 /* -------------------------------------------------------------------------
900 static const struct mix_ent mix_devs
[SOUND_MIXER_NRDEVICES
] = {
901 { 2, 6, 1, 7 }, /* SOUND_MIXER_VOLUME */
902 { 0, 0, 0, 0 }, /* SOUND_MIXER_BASS */
903 { 0, 0, 0, 0 }, /* SOUND_MIXER_TREBLE */
904 { 0, 0, 0, 0 }, /* SOUND_MIXER_SYNTH */
905 { 0, 0, 0, 0 }, /* SOUND_MIXER_PCM */
906 { 0, 0, 0, 0 }, /* SOUND_MIXER_SPEAKER */
907 { 0, 4, 6, 31 }, /* SOUND_MIXER_LINE */
908 { 2, 6, 4, 3 }, /* SOUND_MIXER_MIC */
909 { 0, 0, 0, 0 }, /* SOUND_MIXER_CD */
910 { 0, 0, 0, 0 }, /* SOUND_MIXER_IMIX */
911 { 0, 0, 0, 0 }, /* SOUND_MIXER_ALTPCM */
913 { 3, 7, 0, 10 }, /* SOUND_MIXER_RECLEV */
914 { 0, 0, 0, 0 }, /* SOUND_MIXER_IGAIN */
916 { 0, 0, 0, 0 }, /* SOUND_MIXER_RECLEV */
917 { 3, 7, 0, 7 }, /* SOUND_MIXER_IGAIN */
919 { 0, 0, 0, 0 }, /* SOUND_MIXER_OGAIN */
920 { 0, 4, 1, 31 }, /* SOUND_MIXER_LINE1 */
921 { 1, 5, 6, 31 }, /* SOUND_MIXER_LINE2 */
922 { 0, 0, 0, 0 }, /* SOUND_MIXER_LINE3 */
923 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL1 */
924 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL2 */
925 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL3 */
926 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEIN */
927 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEOUT */
928 { 0, 0, 0, 0 }, /* SOUND_MIXER_VIDEO */
929 { 0, 0, 0, 0 }, /* SOUND_MIXER_RADIO */
930 { 0, 0, 0, 0 } /* SOUND_MIXER_MONITOR */
934 waveartist_mixer_update(struct wavnc_info
*devc
, int whichDev
)
936 unsigned int lev_left
, lev_right
;
938 lev_left
= devc
->levels
[whichDev
] & 0xff;
939 lev_right
= devc
->levels
[whichDev
] >> 8;
946 #define SCALE(lev,max) ((lev) * (max) / 100)
948 if (machine_is_netwinder() && whichDev
== SOUND_MIXER_PHONEOUT
)
949 whichDev
= SOUND_MIXER_VOLUME
;
951 if (mix_devs
[whichDev
].reg_l
|| mix_devs
[whichDev
].reg_r
) {
952 const struct mix_ent
*mix
= mix_devs
+ whichDev
;
953 unsigned int mask
, left
, right
;
955 mask
= mix
->max
<< mix
->shift
;
956 lev_left
= SCALE(lev_left
, mix
->max
) << mix
->shift
;
957 lev_right
= SCALE(lev_right
, mix
->max
) << mix
->shift
;
959 /* read left setting */
960 left
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
|
963 /* read right setting */
964 right
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
|
967 left
= (left
& ~mask
) | (lev_left
& mask
);
968 right
= (right
& ~mask
) | (lev_right
& mask
);
970 /* write left,right back */
971 waveartist_cmd3(devc
, WACMD_SET_MIXER
, left
, right
);
974 case SOUND_MIXER_PCM
:
975 waveartist_cmd3(devc
, WACMD_SET_LEVEL
,
976 SCALE(lev_left
, 32767),
977 SCALE(lev_right
, 32767));
980 case SOUND_MIXER_SYNTH
:
981 waveartist_cmd3(devc
, 0x0100 | WACMD_SET_LEVEL
,
982 SCALE(lev_left
, 32767),
983 SCALE(lev_right
, 32767));
990 * Set the ADC MUX to the specified values. We do NOT do any
991 * checking of the values passed, since we assume that the
992 * relevant *_select_input function has done that for us.
995 waveartist_set_adc_mux(struct wavnc_info
*devc
, char left_dev
,
998 unsigned int reg_08
, reg_09
;
1000 reg_08
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
| 0x0800);
1001 reg_09
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
| 0x0900);
1003 reg_08
= (reg_08
& ~0x3f) | right_dev
<< 3 | left_dev
;
1005 waveartist_cmd3(devc
, WACMD_SET_MIXER
, reg_08
, reg_09
);
1009 * Decode a recording mask into a mixer selection as follows:
1011 * OSS Source WA Source Actual source
1012 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
1013 * SOUND_MASK_LINE Line Line in
1014 * SOUND_MASK_LINE1 Aux 1 Aux 1 in
1015 * SOUND_MASK_LINE2 Aux 2 Aux 2 in
1016 * SOUND_MASK_MIC Mic Microphone
1019 waveartist_select_input(struct wavnc_info
*devc
, unsigned int recmask
,
1020 unsigned char *dev_l
, unsigned char *dev_r
)
1022 unsigned int recdev
= ADC_MUX_NONE
;
1024 if (recmask
& SOUND_MASK_IMIX
) {
1025 recmask
= SOUND_MASK_IMIX
;
1026 recdev
= ADC_MUX_MIXER
;
1027 } else if (recmask
& SOUND_MASK_LINE2
) {
1028 recmask
= SOUND_MASK_LINE2
;
1029 recdev
= ADC_MUX_AUX2
;
1030 } else if (recmask
& SOUND_MASK_LINE1
) {
1031 recmask
= SOUND_MASK_LINE1
;
1032 recdev
= ADC_MUX_AUX1
;
1033 } else if (recmask
& SOUND_MASK_LINE
) {
1034 recmask
= SOUND_MASK_LINE
;
1035 recdev
= ADC_MUX_LINE
;
1036 } else if (recmask
& SOUND_MASK_MIC
) {
1037 recmask
= SOUND_MASK_MIC
;
1038 recdev
= ADC_MUX_MIC
;
1041 *dev_l
= *dev_r
= recdev
;
1047 waveartist_decode_mixer(struct wavnc_info
*devc
, int dev
,
1048 unsigned char lev_l
,
1049 unsigned char lev_r
)
1052 case SOUND_MIXER_VOLUME
:
1053 case SOUND_MIXER_SYNTH
:
1054 case SOUND_MIXER_PCM
:
1055 case SOUND_MIXER_LINE
:
1056 case SOUND_MIXER_MIC
:
1057 case SOUND_MIXER_IGAIN
:
1058 case SOUND_MIXER_LINE1
:
1059 case SOUND_MIXER_LINE2
:
1060 devc
->levels
[dev
] = lev_l
| lev_r
<< 8;
1063 case SOUND_MIXER_IMIX
:
1074 static int waveartist_get_mixer(struct wavnc_info
*devc
, int dev
)
1076 return devc
->levels
[dev
];
1079 static const struct waveartist_mixer_info waveartist_mixer
= {
1080 .supported_devs
= SUPPORTED_MIXER_DEVICES
| SOUND_MASK_IGAIN
,
1081 .recording_devs
= SOUND_MASK_LINE
| SOUND_MASK_MIC
|
1082 SOUND_MASK_LINE1
| SOUND_MASK_LINE2
|
1084 .stereo_devs
= (SUPPORTED_MIXER_DEVICES
| SOUND_MASK_IGAIN
) & ~
1085 (SOUND_MASK_SPEAKER
| SOUND_MASK_IMIX
),
1086 .select_input
= waveartist_select_input
,
1087 .decode_mixer
= waveartist_decode_mixer
,
1088 .get_mixer
= waveartist_get_mixer
,
1092 waveartist_set_recmask(struct wavnc_info
*devc
, unsigned int recmask
)
1094 unsigned char dev_l
, dev_r
;
1096 recmask
&= devc
->mix
->recording_devs
;
1099 * If more than one recording device selected,
1100 * disable the device that is currently in use.
1102 if (hweight32(recmask
) > 1)
1103 recmask
&= ~devc
->recmask
;
1106 * Translate the recording device mask into
1107 * the ADC multiplexer settings.
1109 devc
->recmask
= devc
->mix
->select_input(devc
, recmask
,
1112 waveartist_set_adc_mux(devc
, dev_l
, dev_r
);
1116 waveartist_set_mixer(struct wavnc_info
*devc
, int dev
, unsigned int level
)
1118 unsigned int lev_left
= level
& 0x00ff;
1119 unsigned int lev_right
= (level
& 0xff00) >> 8;
1123 if (lev_right
> 100)
1127 * Mono devices have their right volume forced to their
1128 * left volume. (from ALSA driver OSS emulation).
1130 if (!(devc
->mix
->stereo_devs
& (1 << dev
)))
1131 lev_right
= lev_left
;
1133 dev
= devc
->mix
->decode_mixer(devc
, dev
, lev_left
, lev_right
);
1136 waveartist_mixer_update(devc
, dev
);
1138 return dev
< 0 ? dev
: 0;
1142 waveartist_mixer_ioctl(int dev
, unsigned int cmd
, void __user
* arg
)
1144 struct wavnc_info
*devc
= (struct wavnc_info
*)audio_devs
[dev
]->devc
;
1145 int ret
= 0, val
, nr
;
1148 * All SOUND_MIXER_* ioctls use type 'M'
1150 if (((cmd
>> 8) & 255) != 'M')
1151 return -ENOIOCTLCMD
;
1153 #ifdef CONFIG_ARCH_NETWINDER
1154 if (machine_is_netwinder()) {
1155 ret
= vnc_private_ioctl(dev
, cmd
, arg
);
1156 if (ret
!= -ENOIOCTLCMD
)
1165 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
) {
1166 if (get_user(val
, (int __user
*)arg
))
1170 case SOUND_MIXER_RECSRC
:
1171 waveartist_set_recmask(devc
, val
);
1176 if (nr
< SOUND_MIXER_NRDEVICES
&&
1177 devc
->mix
->supported_devs
& (1 << nr
))
1178 ret
= waveartist_set_mixer(devc
, nr
, val
);
1182 if (ret
== 0 && _SIOC_DIR(cmd
) & _SIOC_READ
) {
1186 case SOUND_MIXER_RECSRC
:
1187 ret
= devc
->recmask
;
1190 case SOUND_MIXER_DEVMASK
:
1191 ret
= devc
->mix
->supported_devs
;
1194 case SOUND_MIXER_STEREODEVS
:
1195 ret
= devc
->mix
->stereo_devs
;
1198 case SOUND_MIXER_RECMASK
:
1199 ret
= devc
->mix
->recording_devs
;
1202 case SOUND_MIXER_CAPS
:
1203 ret
= SOUND_CAP_EXCL_INPUT
;
1207 if (nr
< SOUND_MIXER_NRDEVICES
)
1208 ret
= devc
->mix
->get_mixer(devc
, nr
);
1213 ret
= put_user(ret
, (int __user
*)arg
) ? -EFAULT
: 0;
1219 static struct mixer_operations waveartist_mixer_operations
=
1221 .owner
= THIS_MODULE
,
1223 .name
= "WaveArtist",
1224 .ioctl
= waveartist_mixer_ioctl
1228 waveartist_mixer_reset(struct wavnc_info
*devc
)
1232 if (debug_flg
& DEBUG_MIXER
)
1233 printk("%s: mixer_reset\n", devc
->hw
.name
);
1238 waveartist_cmd1(devc
, WACMD_RST_MIXER
);
1241 * set input for ADC to come from 'quiet'
1242 * turn on default modes
1244 waveartist_cmd3(devc
, WACMD_SET_MIXER
, 0x9800, 0xa836);
1247 * set mixer input select to none, RX filter gains 0 dB
1249 waveartist_cmd3(devc
, WACMD_SET_MIXER
, 0x4c00, 0x8c00);
1252 * set bit 0 reg 2 to 1 - unmute MonoOut
1254 waveartist_cmd3(devc
, WACMD_SET_MIXER
, 0x2801, 0x6800);
1256 /* set default input device = internal mic
1257 * current recording device = none
1259 waveartist_set_recmask(devc
, 0);
1261 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
1262 waveartist_mixer_update(devc
, i
);
1265 static int __init
waveartist_init(struct wavnc_info
*devc
)
1267 struct wavnc_port_info
*portc
;
1268 char rev
[3], dev_name
[64];
1271 if (waveartist_reset(devc
))
1274 sprintf(dev_name
, "%s (%s", devc
->hw
.name
, devc
->chip_name
);
1276 if (waveartist_getrev(devc
, rev
)) {
1277 strcat(dev_name
, " rev. ");
1278 strcat(dev_name
, rev
);
1280 strcat(dev_name
, ")");
1282 conf_printf2(dev_name
, devc
->hw
.io_base
, devc
->hw
.irq
,
1283 devc
->hw
.dma
, devc
->hw
.dma2
);
1285 portc
= kzalloc(sizeof(struct wavnc_port_info
), GFP_KERNEL
);
1289 my_dev
= sound_install_audiodrv(AUDIO_DRIVER_VERSION
, dev_name
,
1290 &waveartist_audio_driver
, sizeof(struct audio_driver
),
1291 devc
->audio_flags
, AFMT_U8
| AFMT_S16_LE
| AFMT_S8
,
1292 devc
, devc
->hw
.dma
, devc
->hw
.dma2
);
1297 audio_devs
[my_dev
]->portc
= portc
;
1299 waveartist_mixer_reset(devc
);
1302 * clear any pending interrupt
1304 waveartist_iack(devc
);
1306 if (request_irq(devc
->hw
.irq
, waveartist_intr
, 0, devc
->hw
.name
, devc
) < 0) {
1307 printk(KERN_ERR
"%s: IRQ %d in use\n",
1308 devc
->hw
.name
, devc
->hw
.irq
);
1312 if (sound_alloc_dma(devc
->hw
.dma
, devc
->hw
.name
)) {
1313 printk(KERN_ERR
"%s: Can't allocate DMA%d\n",
1314 devc
->hw
.name
, devc
->hw
.dma
);
1318 if (devc
->hw
.dma
!= devc
->hw
.dma2
&& devc
->hw
.dma2
!= NO_DMA
)
1319 if (sound_alloc_dma(devc
->hw
.dma2
, devc
->hw
.name
)) {
1320 printk(KERN_ERR
"%s: can't allocate DMA%d\n",
1321 devc
->hw
.name
, devc
->hw
.dma2
);
1325 waveartist_set_ctlr(&devc
->hw
, 0, DMA1_IE
| DMA0_IE
);
1327 audio_devs
[my_dev
]->mixer_dev
=
1328 sound_install_mixer(MIXER_DRIVER_VERSION
,
1330 &waveartist_mixer_operations
,
1331 sizeof(struct mixer_operations
),
1337 sound_free_dma(devc
->hw
.dma
);
1340 free_irq(devc
->hw
.irq
, devc
);
1343 sound_unload_audiodev(my_dev
);
1352 static int __init
probe_waveartist(struct address_info
*hw_config
)
1354 struct wavnc_info
*devc
= &adev_info
[nr_waveartist_devs
];
1356 if (nr_waveartist_devs
>= MAX_AUDIO_DEV
) {
1357 printk(KERN_WARNING
"waveartist: too many audio devices\n");
1361 if (!request_region(hw_config
->io_base
, 15, hw_config
->name
)) {
1362 printk(KERN_WARNING
"WaveArtist: I/O port conflict\n");
1366 if (hw_config
->irq
> 15 || hw_config
->irq
< 0) {
1367 release_region(hw_config
->io_base
, 15);
1368 printk(KERN_WARNING
"WaveArtist: Bad IRQ %d\n",
1373 if (hw_config
->dma
!= 3) {
1374 release_region(hw_config
->io_base
, 15);
1375 printk(KERN_WARNING
"WaveArtist: Bad DMA %d\n",
1380 hw_config
->name
= "WaveArtist";
1381 devc
->hw
= *hw_config
;
1382 devc
->open_mode
= 0;
1383 devc
->chip_name
= "RWA-010";
1389 attach_waveartist(struct address_info
*hw
, const struct waveartist_mixer_info
*mix
)
1391 struct wavnc_info
*devc
= &adev_info
[nr_waveartist_devs
];
1394 * NOTE! If irq < 0, there is another driver which has allocated the
1395 * IRQ so that this driver doesn't need to allocate/deallocate it.
1396 * The actually used IRQ is ABS(irq).
1399 devc
->hw
.irq
= (hw
->irq
> 0) ? hw
->irq
: 0;
1400 devc
->open_mode
= 0;
1401 devc
->playback_dev
= 0;
1402 devc
->record_dev
= 0;
1403 devc
->audio_flags
= DMA_AUTOMODE
;
1404 devc
->levels
= levels
;
1406 if (hw
->dma
!= hw
->dma2
&& hw
->dma2
!= NO_DMA
)
1407 devc
->audio_flags
|= DMA_DUPLEX
;
1410 devc
->dev_no
= waveartist_init(devc
);
1412 if (devc
->dev_no
< 0)
1413 release_region(hw
->io_base
, 15);
1415 #ifdef CONFIG_ARCH_NETWINDER
1416 if (machine_is_netwinder()) {
1417 setup_timer(&vnc_timer
, vnc_slider_tick
,
1418 nr_waveartist_devs
);
1419 mod_timer(&vnc_timer
, jiffies
);
1421 vnc_configure_mixer(devc
, 0);
1423 devc
->no_autoselect
= 1;
1426 nr_waveartist_devs
+= 1;
1430 static void __exit
unload_waveartist(struct address_info
*hw
)
1432 struct wavnc_info
*devc
= NULL
;
1435 for (i
= 0; i
< nr_waveartist_devs
; i
++)
1436 if (hw
->io_base
== adev_info
[i
].hw
.io_base
) {
1437 devc
= adev_info
+ i
;
1444 #ifdef CONFIG_ARCH_NETWINDER
1445 if (machine_is_netwinder())
1446 del_timer(&vnc_timer
);
1449 release_region(devc
->hw
.io_base
, 15);
1451 waveartist_set_ctlr(&devc
->hw
, DMA1_IE
|DMA0_IE
, 0);
1453 if (devc
->hw
.irq
>= 0)
1454 free_irq(devc
->hw
.irq
, devc
);
1456 sound_free_dma(devc
->hw
.dma
);
1458 if (devc
->hw
.dma
!= devc
->hw
.dma2
&&
1459 devc
->hw
.dma2
!= NO_DMA
)
1460 sound_free_dma(devc
->hw
.dma2
);
1462 mixer
= audio_devs
[devc
->dev_no
]->mixer_dev
;
1465 sound_unload_mixerdev(mixer
);
1467 if (devc
->dev_no
>= 0)
1468 sound_unload_audiodev(devc
->dev_no
);
1470 nr_waveartist_devs
-= 1;
1472 for (; i
< nr_waveartist_devs
; i
++)
1473 adev_info
[i
] = adev_info
[i
+ 1];
1475 printk(KERN_WARNING
"waveartist: can't find device "
1479 #ifdef CONFIG_ARCH_NETWINDER
1482 * Rebel.com Netwinder specifics...
1485 #include <asm/hardware/dec21285.h>
1487 #define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
1489 #define MIXER_PRIVATE3_RESET 0x53570000
1490 #define MIXER_PRIVATE3_READ 0x53570001
1491 #define MIXER_PRIVATE3_WRITE 0x53570002
1493 #define VNC_MUTE_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
1494 #define VNC_MUTE_LINE_OUT 0x10
1495 #define VNC_PHONE_DETECT 0x20
1496 #define VNC_HANDSET_DETECT 0x40
1497 #define VNC_DISABLE_AUTOSWITCH 0x80
1500 vnc_mute_spkr(struct wavnc_info
*devc
)
1502 unsigned long flags
;
1504 raw_spin_lock_irqsave(&nw_gpio_lock
, flags
);
1505 nw_cpld_modify(CPLD_UNMUTE
, devc
->spkr_mute_state
? 0 : CPLD_UNMUTE
);
1506 raw_spin_unlock_irqrestore(&nw_gpio_lock
, flags
);
1510 vnc_mute_lout(struct wavnc_info
*devc
)
1512 unsigned int left
, right
;
1514 left
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
);
1515 right
= waveartist_cmd1_r(devc
, WACMD_GET_LEVEL
| 0x400);
1517 if (devc
->line_mute_state
) {
1524 waveartist_cmd3(devc
, WACMD_SET_MIXER
, left
, right
);
1529 vnc_volume_slider(struct wavnc_info
*devc
)
1531 static signed int old_slider_volume
;
1532 unsigned long flags
;
1533 signed int volume
= 255;
1535 *CSR_TIMER1_LOAD
= 0x00ffffff;
1537 spin_lock_irqsave(&waveartist_lock
, flags
);
1540 *CSR_TIMER1_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_DIV1
;
1542 while (volume
&& (inb(0x201) & 0x01))
1545 *CSR_TIMER1_CNTL
= 0;
1547 spin_unlock_irqrestore(&waveartist_lock
,flags
);
1549 volume
= 0x00ffffff - *CSR_TIMER1_VALUE
;
1553 volume
= 150 - (volume
>> 5);
1555 volume
= (volume
>> 6) - 25;
1565 * slider quite often reads +-8, so debounce this random noise
1567 if (abs(volume
- old_slider_volume
) > 7) {
1568 old_slider_volume
= volume
;
1570 if (debug_flg
& DEBUG_MIXER
)
1571 printk(KERN_DEBUG
"Slider volume: %d.\n", volume
);
1574 return old_slider_volume
;
1578 * Decode a recording mask into a mixer selection on the NetWinder
1581 * OSS Source WA Source Actual source
1582 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
1583 * SOUND_MASK_LINE Line Line in
1584 * SOUND_MASK_LINE1 Left Mic Handset
1585 * SOUND_MASK_PHONEIN Left Aux Telephone microphone
1586 * SOUND_MASK_MIC Right Mic Builtin microphone
1589 netwinder_select_input(struct wavnc_info
*devc
, unsigned int recmask
,
1590 unsigned char *dev_l
, unsigned char *dev_r
)
1592 unsigned int recdev_l
= ADC_MUX_NONE
, recdev_r
= ADC_MUX_NONE
;
1594 if (recmask
& SOUND_MASK_IMIX
) {
1595 recmask
= SOUND_MASK_IMIX
;
1596 recdev_l
= ADC_MUX_MIXER
;
1597 recdev_r
= ADC_MUX_MIXER
;
1598 } else if (recmask
& SOUND_MASK_LINE
) {
1599 recmask
= SOUND_MASK_LINE
;
1600 recdev_l
= ADC_MUX_LINE
;
1601 recdev_r
= ADC_MUX_LINE
;
1602 } else if (recmask
& SOUND_MASK_LINE1
) {
1603 recmask
= SOUND_MASK_LINE1
;
1604 waveartist_cmd1(devc
, WACMD_SET_MONO
); /* left */
1605 recdev_l
= ADC_MUX_MIC
;
1606 recdev_r
= ADC_MUX_NONE
;
1607 } else if (recmask
& SOUND_MASK_PHONEIN
) {
1608 recmask
= SOUND_MASK_PHONEIN
;
1609 waveartist_cmd1(devc
, WACMD_SET_MONO
); /* left */
1610 recdev_l
= ADC_MUX_AUX1
;
1611 recdev_r
= ADC_MUX_NONE
;
1612 } else if (recmask
& SOUND_MASK_MIC
) {
1613 recmask
= SOUND_MASK_MIC
;
1614 waveartist_cmd1(devc
, WACMD_SET_MONO
| 0x100); /* right */
1615 recdev_l
= ADC_MUX_NONE
;
1616 recdev_r
= ADC_MUX_MIC
;
1626 netwinder_decode_mixer(struct wavnc_info
*devc
, int dev
, unsigned char lev_l
,
1627 unsigned char lev_r
)
1630 case SOUND_MIXER_VOLUME
:
1631 case SOUND_MIXER_SYNTH
:
1632 case SOUND_MIXER_PCM
:
1633 case SOUND_MIXER_LINE
:
1634 case SOUND_MIXER_IGAIN
:
1635 devc
->levels
[dev
] = lev_l
| lev_r
<< 8;
1638 case SOUND_MIXER_MIC
: /* right mic only */
1639 devc
->levels
[SOUND_MIXER_MIC
] &= 0xff;
1640 devc
->levels
[SOUND_MIXER_MIC
] |= lev_l
<< 8;
1643 case SOUND_MIXER_LINE1
: /* left mic only */
1644 devc
->levels
[SOUND_MIXER_MIC
] &= 0xff00;
1645 devc
->levels
[SOUND_MIXER_MIC
] |= lev_l
;
1646 dev
= SOUND_MIXER_MIC
;
1649 case SOUND_MIXER_PHONEIN
: /* left aux only */
1650 devc
->levels
[SOUND_MIXER_LINE1
] = lev_l
;
1651 dev
= SOUND_MIXER_LINE1
;
1654 case SOUND_MIXER_IMIX
:
1655 case SOUND_MIXER_PHONEOUT
:
1665 static int netwinder_get_mixer(struct wavnc_info
*devc
, int dev
)
1670 case SOUND_MIXER_VOLUME
:
1671 case SOUND_MIXER_SYNTH
:
1672 case SOUND_MIXER_PCM
:
1673 case SOUND_MIXER_LINE
:
1674 case SOUND_MIXER_IGAIN
:
1675 levels
= devc
->levels
[dev
];
1678 case SOUND_MIXER_MIC
: /* builtin mic: right mic only */
1679 levels
= devc
->levels
[SOUND_MIXER_MIC
] >> 8;
1680 levels
|= levels
<< 8;
1683 case SOUND_MIXER_LINE1
: /* handset mic: left mic only */
1684 levels
= devc
->levels
[SOUND_MIXER_MIC
] & 0xff;
1685 levels
|= levels
<< 8;
1688 case SOUND_MIXER_PHONEIN
: /* phone mic: left aux1 only */
1689 levels
= devc
->levels
[SOUND_MIXER_LINE1
] & 0xff;
1690 levels
|= levels
<< 8;
1701 * Waveartist specific mixer information.
1703 static const struct waveartist_mixer_info netwinder_mixer
= {
1704 .supported_devs
= SOUND_MASK_VOLUME
| SOUND_MASK_SYNTH
|
1705 SOUND_MASK_PCM
| SOUND_MASK_SPEAKER
|
1706 SOUND_MASK_LINE
| SOUND_MASK_MIC
|
1707 SOUND_MASK_IMIX
| SOUND_MASK_LINE1
|
1708 SOUND_MASK_PHONEIN
| SOUND_MASK_PHONEOUT
|
1711 .recording_devs
= SOUND_MASK_LINE
| SOUND_MASK_MIC
|
1712 SOUND_MASK_IMIX
| SOUND_MASK_LINE1
|
1715 .stereo_devs
= SOUND_MASK_VOLUME
| SOUND_MASK_SYNTH
|
1716 SOUND_MASK_PCM
| SOUND_MASK_LINE
|
1717 SOUND_MASK_IMIX
| SOUND_MASK_IGAIN
,
1719 .select_input
= netwinder_select_input
,
1720 .decode_mixer
= netwinder_decode_mixer
,
1721 .get_mixer
= netwinder_get_mixer
,
1725 vnc_configure_mixer(struct wavnc_info
*devc
, unsigned int recmask
)
1727 if (!devc
->no_autoselect
) {
1728 if (devc
->handset_detect
) {
1729 recmask
= SOUND_MASK_LINE1
;
1730 devc
->spkr_mute_state
= devc
->line_mute_state
= 1;
1731 } else if (devc
->telephone_detect
) {
1732 recmask
= SOUND_MASK_PHONEIN
;
1733 devc
->spkr_mute_state
= devc
->line_mute_state
= 1;
1735 /* unless someone has asked for LINE-IN,
1738 if ((devc
->recmask
& SOUND_MASK_LINE
) == 0)
1739 devc
->recmask
= SOUND_MASK_MIC
;
1740 devc
->spkr_mute_state
= devc
->line_mute_state
= 0;
1742 vnc_mute_spkr(devc
);
1743 vnc_mute_lout(devc
);
1745 if (recmask
!= devc
->recmask
)
1746 waveartist_set_recmask(devc
, recmask
);
1751 vnc_slider(struct wavnc_info
*devc
)
1753 signed int slider_volume
;
1754 unsigned int temp
, old_hs
, old_td
;
1757 * read the "buttons" state.
1758 * Bit 4 = 0 means handset present
1759 * Bit 5 = 1 means phone offhook
1763 old_hs
= devc
->handset_detect
;
1764 old_td
= devc
->telephone_detect
;
1766 devc
->handset_detect
= !(temp
& 0x10);
1767 devc
->telephone_detect
= !!(temp
& 0x20);
1769 if (!devc
->no_autoselect
&&
1770 (old_hs
!= devc
->handset_detect
||
1771 old_td
!= devc
->telephone_detect
))
1772 vnc_configure_mixer(devc
, devc
->recmask
);
1774 slider_volume
= vnc_volume_slider(devc
);
1777 * If we're using software controlled volume, and
1778 * the slider moves by more than 20%, then we
1779 * switch back to slider controlled volume.
1781 if (abs(devc
->slider_vol
- slider_volume
) > 20)
1782 devc
->use_slider
= 1;
1785 * use only left channel
1787 temp
= levels
[SOUND_MIXER_VOLUME
] & 0xFF;
1789 if (slider_volume
!= temp
&& devc
->use_slider
) {
1790 devc
->slider_vol
= slider_volume
;
1792 waveartist_set_mixer(devc
, SOUND_MIXER_VOLUME
,
1793 slider_volume
| slider_volume
<< 8);
1802 vnc_slider_tick(unsigned long data
)
1806 if (vnc_slider(adev_info
+ data
))
1807 next_timeout
= 5; // mixer reported change
1809 next_timeout
= VNC_TIMER_PERIOD
;
1811 mod_timer(&vnc_timer
, jiffies
+ next_timeout
);
1815 vnc_private_ioctl(int dev
, unsigned int cmd
, int __user
* arg
)
1817 struct wavnc_info
*devc
= (struct wavnc_info
*)audio_devs
[dev
]->devc
;
1821 case SOUND_MIXER_PRIVATE1
:
1823 u_int prev_spkr_mute
, prev_line_mute
, prev_auto_state
;
1826 if (get_user(val
, arg
))
1829 /* check if parameter is logical */
1830 if (val
& ~(VNC_MUTE_INTERNAL_SPKR
|
1832 VNC_DISABLE_AUTOSWITCH
))
1835 prev_auto_state
= devc
->no_autoselect
;
1836 prev_spkr_mute
= devc
->spkr_mute_state
;
1837 prev_line_mute
= devc
->line_mute_state
;
1839 devc
->no_autoselect
= (val
& VNC_DISABLE_AUTOSWITCH
) ? 1 : 0;
1840 devc
->spkr_mute_state
= (val
& VNC_MUTE_INTERNAL_SPKR
) ? 1 : 0;
1841 devc
->line_mute_state
= (val
& VNC_MUTE_LINE_OUT
) ? 1 : 0;
1843 if (prev_spkr_mute
!= devc
->spkr_mute_state
)
1844 vnc_mute_spkr(devc
);
1846 if (prev_line_mute
!= devc
->line_mute_state
)
1847 vnc_mute_lout(devc
);
1849 if (prev_auto_state
!= devc
->no_autoselect
)
1850 vnc_configure_mixer(devc
, devc
->recmask
);
1855 case SOUND_MIXER_PRIVATE2
:
1856 if (get_user(val
, arg
))
1860 #define VNC_SOUND_PAUSE 0x53 //to pause the DSP
1861 #define VNC_SOUND_RESUME 0x57 //to unpause the DSP
1862 case VNC_SOUND_PAUSE
:
1863 waveartist_cmd1(devc
, 0x16);
1866 case VNC_SOUND_RESUME
:
1867 waveartist_cmd1(devc
, 0x18);
1875 /* private ioctl to allow bulk access to waveartist */
1876 case SOUND_MIXER_PRIVATE3
:
1878 unsigned long flags
;
1879 int mixer_reg
[15], i
, val
;
1881 if (get_user(val
, arg
))
1883 if (copy_from_user(mixer_reg
, (void *)val
, sizeof(mixer_reg
)))
1886 switch (mixer_reg
[14]) {
1887 case MIXER_PRIVATE3_RESET
:
1888 waveartist_mixer_reset(devc
);
1891 case MIXER_PRIVATE3_WRITE
:
1892 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[0], mixer_reg
[4]);
1893 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[1], mixer_reg
[5]);
1894 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[2], mixer_reg
[6]);
1895 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[3], mixer_reg
[7]);
1896 waveartist_cmd3(devc
, WACMD_SET_MIXER
, mixer_reg
[8], mixer_reg
[9]);
1898 waveartist_cmd3(devc
, WACMD_SET_LEVEL
, mixer_reg
[10], mixer_reg
[11]);
1899 waveartist_cmd3(devc
, WACMD_SET_LEVEL
, mixer_reg
[12], mixer_reg
[13]);
1902 case MIXER_PRIVATE3_READ
:
1903 spin_lock_irqsave(&waveartist_lock
, flags
);
1905 for (i
= 0x30; i
< 14 << 8; i
+= 1 << 8)
1906 waveartist_cmd(devc
, 1, &i
, 1, mixer_reg
+ (i
>> 8));
1908 spin_unlock_irqrestore(&waveartist_lock
, flags
);
1910 if (copy_to_user((void *)val
, mixer_reg
, sizeof(mixer_reg
)))
1920 /* read back the state from PRIVATE1 */
1921 case SOUND_MIXER_PRIVATE4
:
1922 val
= (devc
->spkr_mute_state
? VNC_MUTE_INTERNAL_SPKR
: 0) |
1923 (devc
->line_mute_state
? VNC_MUTE_LINE_OUT
: 0) |
1924 (devc
->handset_detect
? VNC_HANDSET_DETECT
: 0) |
1925 (devc
->telephone_detect
? VNC_PHONE_DETECT
: 0) |
1926 (devc
->no_autoselect
? VNC_DISABLE_AUTOSWITCH
: 0);
1928 return put_user(val
, arg
) ? -EFAULT
: 0;
1931 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
) {
1933 * special case for master volume: if we
1934 * received this call - switch from hw
1935 * volume control to a software volume
1936 * control, till the hw volume is modified
1937 * to signal that user wants to be back in
1940 if ((cmd
& 0xff) == SOUND_MIXER_VOLUME
)
1941 devc
->use_slider
= 0;
1943 /* speaker output */
1944 if ((cmd
& 0xff) == SOUND_MIXER_SPEAKER
) {
1945 unsigned int val
, l
, r
;
1947 if (get_user(val
, arg
))
1951 r
= (val
& 0x7f00) >> 8;
1953 devc
->levels
[SOUND_MIXER_SPEAKER
] = val
| (val
<< 8);
1954 devc
->spkr_mute_state
= (val
<= 50);
1955 vnc_mute_spkr(devc
);
1960 return -ENOIOCTLCMD
;
1965 static struct address_info cfg
;
1967 static int attached
;
1969 static int __initdata io
= 0;
1970 static int __initdata irq
= 0;
1971 static int __initdata dma
= 0;
1972 static int __initdata dma2
= 0;
1975 static int __init
init_waveartist(void)
1977 const struct waveartist_mixer_info
*mix
;
1979 if (!io
&& machine_is_netwinder()) {
1981 * The NetWinder WaveArtist is at a fixed address.
1982 * If the user does not supply an address, use the
1983 * well-known parameters.
1991 mix
= &waveartist_mixer
;
1992 #ifdef CONFIG_ARCH_NETWINDER
1993 if (machine_is_netwinder())
1994 mix
= &netwinder_mixer
;
2002 if (!probe_waveartist(&cfg
))
2005 attach_waveartist(&cfg
, mix
);
2011 static void __exit
cleanup_waveartist(void)
2014 unload_waveartist(&cfg
);
2017 module_init(init_waveartist
);
2018 module_exit(cleanup_waveartist
);
2021 static int __init
setup_waveartist(char *str
)
2023 /* io, irq, dma, dma2 */
2026 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
2035 __setup("waveartist=", setup_waveartist
);
2038 MODULE_DESCRIPTION("Rockwell WaveArtist RWA-010 sound driver");
2039 module_param(io
, int, 0); /* IO base */
2040 module_param(irq
, int, 0); /* IRQ */
2041 module_param(dma
, int, 0); /* DMA */
2042 module_param(dma2
, int, 0); /* DMA2 */
2043 MODULE_LICENSE("GPL");