Import 2.3.52pre1
[davej-history.git] / drivers / sound / waveartist.c
blob75d1a897750b6f111d3974046e816919ae7f6453
1 /*
2 * linux/drivers/sound/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
19 * for more info.
22 /* Debugging */
23 #define DEBUG_CMD 1
24 #define DEBUG_OUT 2
25 #define DEBUG_IN 4
26 #define DEBUG_INTR 8
27 #define DEBUG_MIXER 16
28 #define DEBUG_TRIGGER 32
30 #define debug_flg (0)
32 #include <linux/module.h>
33 #include <linux/init.h>
34 #include <linux/config.h>
35 #include <linux/sched.h>
36 #include <linux/interrupt.h>
37 #include <linux/delay.h>
38 #include <linux/smp.h>
39 #include <linux/spinlock.h>
41 #include <asm/dec21285.h>
42 #include <asm/hardware.h>
43 #include <asm/system.h>
45 #include "soundmodule.h"
46 #include "sound_config.h"
47 #include "waveartist.h"
49 #ifndef _ISA_DMA
50 #define _ISA_DMA(x) (x)
51 #endif
52 #ifndef _ISA_IRQ
53 #define _ISA_IRQ(x) (x)
54 #endif
56 #define POSSIBLE_RECORDING_DEVICES (SOUND_MASK_LINE |\
57 SOUND_MASK_MIC |\
58 SOUND_MASK_LINE1)
60 #define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH |\
61 SOUND_MASK_PCM |\
62 SOUND_MASK_LINE |\
63 SOUND_MASK_MIC |\
64 SOUND_MASK_LINE1 |\
65 SOUND_MASK_RECLEV |\
66 SOUND_MASK_VOLUME |\
67 SOUND_MASK_IMIX)
69 static unsigned short levels[SOUND_MIXER_NRDEVICES] = {
70 0x5555, /* Master Volume */
71 0x0000, /* Bass */
72 0x0000, /* Treble */
73 0x2323, /* Synth (FM) */
74 0x4b4b, /* PCM */
75 0x0000, /* PC Speaker */
76 0x0000, /* Ext Line */
77 0x0000, /* Mic */
78 0x0000, /* CD */
79 0x0000, /* Recording monitor */
80 0x0000, /* SB PCM (ALT PCM) */
81 0x0000, /* Recording level */
82 0x0000, /* Input gain */
83 0x0000, /* Output gain */
84 0x0000, /* Line1 (Aux1) */
85 0x0000, /* Line2 (Aux2) */
86 0x0000, /* Line3 (Aux3) */
87 0x0000, /* Digital1 */
88 0x0000, /* Digital2 */
89 0x0000, /* Digital3 */
90 0x0000, /* Phone In */
91 0x0000, /* Phone Out */
92 0x0000, /* Video */
93 0x0000, /* Radio */
94 0x0000 /* Monitor */
97 typedef struct {
98 struct address_info hw; /* hardware */
99 char *chip_name;
101 int xfer_count;
102 int audio_mode;
103 int open_mode;
104 int audio_flags;
105 int record_dev;
106 int playback_dev;
107 int dev_no;
109 /* Mixer parameters */
110 unsigned short *levels; /* cache of volume settings */
111 int recmask; /* currently enabled recording device! */
112 int supported_devices; /* SUPPORTED_MIXER_DEVICES */
113 int rec_devices; /* POSSIBLE_RECORDING_DEVICES */
115 #ifdef CONFIG_ARCH_NETWINDER
116 signed int slider_vol; /* hardware slider volume */
117 unsigned int handset_detect :1;
118 unsigned int telephone_detect:1;
119 unsigned int no_autoselect :1;/* handset/telephone autoselects a path */
120 unsigned int spkr_mute_state :1;/* set by ioctl or autoselect */
121 unsigned int line_mute_state :1;/* set by ioctl or autoselect */
122 unsigned int use_slider :1;/* use slider setting for o/p vol */
123 #endif
124 } wavnc_info;
126 typedef struct wavnc_port_info {
127 int open_mode;
128 int speed;
129 int channels;
130 int audio_format;
131 } wavnc_port_info;
133 static int nr_waveartist_devs;
134 static wavnc_info adev_info[MAX_AUDIO_DEV];
135 static spinlock_t waveartist_lock = SPIN_LOCK_UNLOCKED;
137 #ifndef machine_is_netwinder
138 #define machine_is_netwinder() 0
139 #endif
141 static struct timer_list vnc_timer;
142 static void vnc_configure_mixer(wavnc_info *devc);
143 static int vnc_private_ioctl(int dev, unsigned int cmd, caddr_t arg);
144 static void vnc_slider_tick(unsigned long data);
146 static inline void
147 waveartist_set_ctlr(struct address_info *hw, unsigned char clear, unsigned char set)
149 unsigned int ctlr_port = hw->io_base + CTLR;
151 clear = ~clear & inb(ctlr_port);
153 outb(clear | set, ctlr_port);
156 /* Toggle IRQ acknowledge line
158 static inline void
159 waveartist_iack(wavnc_info *devc)
161 unsigned int ctlr_port = devc->hw.io_base + CTLR;
162 int old_ctlr;
164 old_ctlr = inb(ctlr_port) & ~IRQ_ACK;
166 outb(old_ctlr | IRQ_ACK, ctlr_port);
167 outb(old_ctlr, ctlr_port);
170 static inline int
171 waveartist_sleep(int timeout_ms)
173 unsigned int timeout = timeout_ms * 10 * HZ / 100;
175 do {
176 current->state = TASK_INTERRUPTIBLE;
177 timeout = schedule_timeout(timeout);
178 } while (timeout);
180 return 0;
183 static int
184 waveartist_reset(wavnc_info *devc)
186 struct address_info *hw = &devc->hw;
187 unsigned int timeout, res = -1;
189 waveartist_set_ctlr(hw, -1, RESET);
190 waveartist_sleep(2);
191 waveartist_set_ctlr(hw, RESET, 0);
193 timeout = 500;
194 do {
195 mdelay(2);
197 if (inb(hw->io_base + STATR) & CMD_RF) {
198 res = inw(hw->io_base + CMDR);
199 if (res == 0x55aa)
200 break;
202 } while (--timeout);
204 if (timeout == 0) {
205 printk(KERN_WARNING "WaveArtist: reset timeout ");
206 if (res != (unsigned int)-1)
207 printk("(res=%04X)", res);
208 printk("\n");
209 return 1;
211 return 0;
214 /* Helper function to send and receive words
215 * from WaveArtist. It handles all the handshaking
216 * and can send or receive multiple words.
218 static int
219 waveartist_cmd(wavnc_info *devc,
220 int nr_cmd, unsigned int *cmd,
221 int nr_resp, unsigned int *resp)
223 unsigned int io_base = devc->hw.io_base;
224 unsigned int timed_out = 0;
225 unsigned int i;
227 if (debug_flg & DEBUG_CMD) {
228 printk("waveartist_cmd: cmd=");
230 for (i = 0; i < nr_cmd; i++)
231 printk("%04X ", cmd[i]);
233 printk("\n");
236 if (inb(io_base + STATR) & CMD_RF) {
237 int old_data;
239 /* flush the port
242 old_data = inw(io_base + CMDR);
244 if (debug_flg & DEBUG_CMD)
245 printk("flushed %04X...", old_data);
247 udelay(10);
250 for (i = 0; !timed_out && i < nr_cmd; i++) {
251 int count;
253 for (count = 5000; count; count--)
254 if (inb(io_base + STATR) & CMD_WE)
255 break;
257 if (!count)
258 timed_out = 1;
259 else
260 outw(cmd[i], io_base + CMDR);
263 for (i = 0; !timed_out && i < nr_resp; i++) {
264 int count;
266 for (count = 5000; count; count--)
267 if (inb(io_base + STATR) & CMD_RF)
268 break;
270 if (!count)
271 timed_out = 1;
272 else
273 resp[i] = inw(io_base + CMDR);
276 if (debug_flg & DEBUG_CMD) {
277 if (!timed_out) {
278 printk("waveartist_cmd: resp=");
280 for (i = 0; i < nr_resp; i++)
281 printk("%04X ", resp[i]);
283 printk("\n");
284 } else
285 printk("waveartist_cmd: timed out\n");
288 return timed_out ? 1 : 0;
292 * Send one command word
294 static inline int
295 waveartist_cmd1(wavnc_info *devc, unsigned int cmd)
297 return waveartist_cmd(devc, 1, &cmd, 0, NULL);
301 * Send one command, receive one word
303 static inline unsigned int
304 waveartist_cmd1_r(wavnc_info *devc, unsigned int cmd)
306 unsigned int ret;
308 waveartist_cmd(devc, 1, &cmd, 1, &ret);
310 return ret;
314 * Send a double command, receive one
315 * word (and throw it away)
317 static inline int
318 waveartist_cmd2(wavnc_info *devc, unsigned int cmd, unsigned int arg)
320 unsigned int vals[2];
322 vals[0] = cmd;
323 vals[1] = arg;
325 return waveartist_cmd(devc, 2, vals, 1, vals);
329 * Send a triple command
331 static inline int
332 waveartist_cmd3(wavnc_info *devc, unsigned int cmd,
333 unsigned int arg1, unsigned int arg2)
335 unsigned int vals[3];
337 vals[0] = cmd;
338 vals[1] = arg1;
339 vals[2] = arg2;
341 return waveartist_cmd(devc, 3, vals, 0, NULL);
344 static int
345 waveartist_getrev(wavnc_info *devc, char *rev)
347 unsigned int temp[2];
348 unsigned int cmd = WACMD_GETREV;
350 waveartist_cmd(devc, 1, &cmd, 2, temp);
352 rev[0] = temp[0] >> 8;
353 rev[1] = temp[0] & 255;
354 rev[2] = '\0';
356 return temp[0];
359 static void waveartist_halt_output(int dev);
360 static void waveartist_halt_input(int dev);
361 static void waveartist_halt(int dev);
362 static void waveartist_trigger(int dev, int state);
364 static int
365 waveartist_open(int dev, int mode)
367 wavnc_info *devc;
368 wavnc_port_info *portc;
369 unsigned long flags;
371 if (dev < 0 || dev >= num_audiodevs)
372 return -ENXIO;
374 devc = (wavnc_info *) audio_devs[dev]->devc;
375 portc = (wavnc_port_info *) audio_devs[dev]->portc;
377 spin_lock_irqsave(&waveartist_lock, flags);
378 if (portc->open_mode || (devc->open_mode & mode)) {
379 spin_unlock_irqrestore(&waveartist_lock, flags);
380 return -EBUSY;
383 devc->audio_mode = 0;
384 devc->open_mode |= mode;
385 portc->open_mode = mode;
386 waveartist_trigger(dev, 0);
388 if (mode & OPEN_READ)
389 devc->record_dev = dev;
390 if (mode & OPEN_WRITE)
391 devc->playback_dev = dev;
392 spin_unlock_irqrestore(&waveartist_lock, flags);
394 return 0;
397 static void
398 waveartist_close(int dev)
400 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
401 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
402 unsigned long flags;
404 spin_lock_irqsave(&waveartist_lock, flags);
406 waveartist_halt(dev);
408 devc->audio_mode = 0;
409 devc->open_mode &= ~portc->open_mode;
410 portc->open_mode = 0;
412 spin_unlock_irqrestore(&waveartist_lock, flags);
415 static void
416 waveartist_output_block(int dev, unsigned long buf, int __count, int intrflag)
418 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
419 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
420 unsigned long flags;
421 unsigned int count = __count;
423 if (debug_flg & DEBUG_OUT)
424 printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
425 buf, count);
427 * 16 bit data
429 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE))
430 count >>= 1;
432 if (portc->channels > 1)
433 count >>= 1;
435 count -= 1;
437 if (devc->audio_mode & PCM_ENABLE_OUTPUT &&
438 audio_devs[dev]->flags & DMA_AUTOMODE &&
439 intrflag &&
440 count == devc->xfer_count) {
441 devc->audio_mode |= PCM_ENABLE_OUTPUT;
442 return; /*
443 * Auto DMA mode on. No need to react
447 spin_lock_irqsave(&waveartist_lock, flags);
450 * set sample count
452 waveartist_cmd2(devc, WACMD_OUTPUTSIZE, count);
454 devc->xfer_count = count;
455 devc->audio_mode |= PCM_ENABLE_OUTPUT;
457 spin_unlock_irqrestore(&waveartist_lock, flags);
460 static void
461 waveartist_start_input(int dev, unsigned long buf, int __count, int intrflag)
463 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
464 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
465 unsigned long flags;
466 unsigned int count = __count;
468 if (debug_flg & DEBUG_IN)
469 printk("waveartist: start input, buf=0x%lx, count=0x%x...\n",
470 buf, count);
472 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
473 count >>= 1;
475 if (portc->channels > 1)
476 count >>= 1;
478 count -= 1;
480 if (devc->audio_mode & PCM_ENABLE_INPUT &&
481 audio_devs[dev]->flags & DMA_AUTOMODE &&
482 intrflag &&
483 count == devc->xfer_count) {
484 devc->audio_mode |= PCM_ENABLE_INPUT;
485 return; /*
486 * Auto DMA mode on. No need to react
490 spin_lock_irqsave(&waveartist_lock, flags);
493 * set sample count
495 waveartist_cmd2(devc, WACMD_INPUTSIZE, count);
497 devc->xfer_count = count;
498 devc->audio_mode |= PCM_ENABLE_INPUT;
500 spin_unlock_irqrestore(&waveartist_lock, flags);
503 static int
504 waveartist_ioctl(int dev, unsigned int cmd, caddr_t arg)
506 return -EINVAL;
509 static unsigned int
510 waveartist_get_speed(wavnc_port_info *portc)
512 unsigned int speed;
515 * program the speed, channels, bits
517 if (portc->speed == 8000)
518 speed = 0x2E71;
519 else if (portc->speed == 11025)
520 speed = 0x4000;
521 else if (portc->speed == 22050)
522 speed = 0x8000;
523 else if (portc->speed == 44100)
524 speed = 0x0;
525 else {
527 * non-standard - just calculate
529 speed = portc->speed << 16;
531 speed = (speed / 44100) & 65535;
534 return speed;
537 static unsigned int
538 waveartist_get_bits(wavnc_port_info *portc)
540 unsigned int bits;
542 if (portc->audio_format == AFMT_S16_LE)
543 bits = 1;
544 else if (portc->audio_format == AFMT_S8)
545 bits = 0;
546 else
547 bits = 2; //default AFMT_U8
549 return bits;
552 static int
553 waveartist_prepare_for_input(int dev, int bsize, int bcount)
555 unsigned long flags;
556 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
557 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
558 unsigned int speed, bits;
560 if (devc->audio_mode)
561 return 0;
563 speed = waveartist_get_speed(portc);
564 bits = waveartist_get_bits(portc);
566 spin_lock_irqsave(&waveartist_lock, flags);
568 if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
569 printk(KERN_WARNING "waveartist: error setting the "
570 "record format to %d\n", portc->audio_format);
572 if (waveartist_cmd2(devc, WACMD_INPUTCHANNELS, portc->channels))
573 printk(KERN_WARNING "waveartist: error setting record "
574 "to %d channels\n", portc->channels);
577 * write cmd SetSampleSpeedTimeConstant
579 if (waveartist_cmd2(devc, WACMD_INPUTSPEED, speed))
580 printk(KERN_WARNING "waveartist: error setting the record "
581 "speed to %dHz.\n", portc->speed);
583 if (waveartist_cmd2(devc, WACMD_INPUTDMA, 1))
584 printk(KERN_WARNING "waveartist: error setting the record "
585 "data path to 0x%X\n", 1);
587 if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
588 printk(KERN_WARNING "waveartist: error setting the record "
589 "format to %d\n", portc->audio_format);
591 devc->xfer_count = 0;
592 spin_unlock_irqrestore(&waveartist_lock, flags);
593 waveartist_halt_input(dev);
595 if (debug_flg & DEBUG_INTR) {
596 printk("WA CTLR reg: 0x%02X.\n",
597 inb(devc->hw.io_base + CTLR));
598 printk("WA STAT reg: 0x%02X.\n",
599 inb(devc->hw.io_base + STATR));
600 printk("WA IRQS reg: 0x%02X.\n",
601 inb(devc->hw.io_base + IRQSTAT));
604 return 0;
607 static int
608 waveartist_prepare_for_output(int dev, int bsize, int bcount)
610 unsigned long flags;
611 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
612 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
613 unsigned int speed, bits;
616 * program the speed, channels, bits
618 speed = waveartist_get_speed(portc);
619 bits = waveartist_get_bits(portc);
621 spin_lock_irqsave(&waveartist_lock, flags);
623 if (waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed) &&
624 waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed))
625 printk(KERN_WARNING "waveartist: error setting the playback "
626 "speed to %dHz.\n", portc->speed);
628 if (waveartist_cmd2(devc, WACMD_OUTPUTCHANNELS, portc->channels))
629 printk(KERN_WARNING "waveartist: error setting the playback "
630 "to %d channels\n", portc->channels);
632 if (waveartist_cmd2(devc, WACMD_OUTPUTDMA, 0))
633 printk(KERN_WARNING "waveartist: error setting the playback "
634 "data path to 0x%X\n", 0);
636 if (waveartist_cmd2(devc, WACMD_OUTPUTFORMAT, bits))
637 printk(KERN_WARNING "waveartist: error setting the playback "
638 "format to %d\n", portc->audio_format);
640 devc->xfer_count = 0;
641 spin_unlock_irqrestore(&waveartist_lock, flags);
642 waveartist_halt_output(dev);
644 if (debug_flg & DEBUG_INTR) {
645 printk("WA CTLR reg: 0x%02X.\n",inb(devc->hw.io_base + CTLR));
646 printk("WA STAT reg: 0x%02X.\n",inb(devc->hw.io_base + STATR));
647 printk("WA IRQS reg: 0x%02X.\n",inb(devc->hw.io_base + IRQSTAT));
650 return 0;
653 static void
654 waveartist_halt(int dev)
656 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
657 wavnc_info *devc;
659 if (portc->open_mode & OPEN_WRITE)
660 waveartist_halt_output(dev);
662 if (portc->open_mode & OPEN_READ)
663 waveartist_halt_input(dev);
665 devc = (wavnc_info *) audio_devs[dev]->devc;
666 devc->audio_mode = 0;
669 static void
670 waveartist_halt_input(int dev)
672 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
673 unsigned long flags;
675 spin_lock_irqsave(&waveartist_lock, flags);
678 * Stop capture
680 waveartist_cmd1(devc, WACMD_INPUTSTOP);
682 devc->audio_mode &= ~PCM_ENABLE_INPUT;
685 * Clear interrupt by toggling
686 * the IRQ_ACK bit in CTRL
688 if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
689 waveartist_iack(devc);
691 // devc->audio_mode &= ~PCM_ENABLE_INPUT;
693 spin_unlock_irqrestore(&waveartist_lock, flags);
696 static void
697 waveartist_halt_output(int dev)
699 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
700 unsigned long flags;
702 spin_lock_irqsave(&waveartist_lock, flags);
704 waveartist_cmd1(devc, WACMD_OUTPUTSTOP);
706 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
709 * Clear interrupt by toggling
710 * the IRQ_ACK bit in CTRL
712 if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
713 waveartist_iack(devc);
715 // devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
717 spin_unlock_irqrestore(&waveartist_lock, flags);
720 static void
721 waveartist_trigger(int dev, int state)
723 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
724 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
725 unsigned long flags;
727 if (debug_flg & DEBUG_TRIGGER) {
728 printk("wavnc: audio trigger ");
729 if (state & PCM_ENABLE_INPUT)
730 printk("in ");
731 if (state & PCM_ENABLE_OUTPUT)
732 printk("out");
733 printk("\n");
736 spin_lock_irqsave(&waveartist_lock, flags);
738 state &= devc->audio_mode;
740 if (portc->open_mode & OPEN_READ &&
741 state & PCM_ENABLE_INPUT)
743 * enable ADC Data Transfer to PC
745 waveartist_cmd1(devc, WACMD_INPUTSTART);
747 if (portc->open_mode & OPEN_WRITE &&
748 state & PCM_ENABLE_OUTPUT)
750 * enable DAC data transfer from PC
752 waveartist_cmd1(devc, WACMD_OUTPUTSTART);
754 spin_unlock_irqrestore(&waveartist_lock, flags);
757 static int
758 waveartist_set_speed(int dev, int arg)
760 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
762 if (arg <= 0)
763 return portc->speed;
765 if (arg < 5000)
766 arg = 5000;
767 if (arg > 44100)
768 arg = 44100;
770 portc->speed = arg;
771 return portc->speed;
775 static short
776 waveartist_set_channels(int dev, short arg)
778 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
780 if (arg != 1 && arg != 2)
781 return portc->channels;
783 portc->channels = arg;
784 return arg;
787 static unsigned int
788 waveartist_set_bits(int dev, unsigned int arg)
790 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
792 if (arg == 0)
793 return portc->audio_format;
795 if ((arg != AFMT_U8) && (arg != AFMT_S16_LE) && (arg != AFMT_S8))
796 arg = AFMT_U8;
798 portc->audio_format = arg;
800 return arg;
803 static struct audio_driver waveartist_audio_driver = {
804 waveartist_open,
805 waveartist_close,
806 waveartist_output_block,
807 waveartist_start_input,
808 waveartist_ioctl,
809 waveartist_prepare_for_input,
810 waveartist_prepare_for_output,
811 waveartist_halt,
812 NULL,
813 NULL,
814 waveartist_halt_input,
815 waveartist_halt_output,
816 waveartist_trigger,
817 waveartist_set_speed,
818 waveartist_set_bits,
819 waveartist_set_channels
823 static void
824 waveartist_intr(int irq, void *dev_id, struct pt_regs *regs)
826 wavnc_info *devc = (wavnc_info *)dev_id;
827 int irqstatus, status;
829 irqstatus = inb(devc->hw.io_base + IRQSTAT);
830 status = inb(devc->hw.io_base + STATR);
832 if (debug_flg & DEBUG_INTR)
833 printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
834 status, irqstatus);
836 if (status & IRQ_REQ) /* Clear interrupt */
837 waveartist_iack(devc);
838 else
839 printk(KERN_WARNING "waveartist: unexpected interrupt\n");
841 if (irqstatus & 0x01) {
842 int temp = 1;
844 /* PCM buffer done
846 if ((status & DMA0) && (devc->audio_mode & PCM_ENABLE_OUTPUT)) {
847 DMAbuf_outputintr(devc->playback_dev, 1);
848 temp = 0;
850 if ((status & DMA1) && (devc->audio_mode & PCM_ENABLE_INPUT)) {
851 DMAbuf_inputintr(devc->record_dev);
852 temp = 0;
854 if (temp) //default:
855 printk(KERN_WARNING "waveartist: Unknown interrupt\n");
857 if (irqstatus & 0x2)
858 // We do not use SB mode natively...
859 printk(KERN_WARNING "waveartist: Unexpected SB interrupt...\n");
862 /* -------------------------------------------------------------------------
863 * Mixer stuff
865 static void
866 waveartist_mixer_update(wavnc_info *devc, int whichDev)
868 unsigned int mask, reg_l, reg_r;
869 unsigned int lev_left, lev_right;
870 unsigned int vals[3];
872 lev_left = devc->levels[whichDev] & 0xff;
873 lev_right = devc->levels[whichDev] >> 8;
875 #define SCALE(lev,max) ((lev) * (max) / 100)
877 if (machine_is_netwinder() && whichDev == SOUND_MIXER_PHONEOUT)
878 whichDev = SOUND_MIXER_VOLUME;
880 switch(whichDev) {
881 case SOUND_MIXER_VOLUME:
882 mask = 0x000e;
883 reg_l = 0x200;
884 reg_r = 0x600;
885 lev_left = SCALE(lev_left, 7) << 1;
886 lev_right = SCALE(lev_right, 7) << 1;
887 break;
889 case SOUND_MIXER_LINE:
890 if ((devc->recmask & SOUND_MASK_LINE) == 0)
891 return;
892 mask = 0x07c0;
893 reg_l = 0x000;
894 reg_r = 0x400;
895 lev_left = SCALE(lev_left, 31) << 6;
896 lev_right = SCALE(lev_right, 31) << 6;
897 break;
899 case SOUND_MIXER_MIC:
900 if ((devc->recmask & SOUND_MASK_MIC) == 0)
901 return;
902 mask = 0x0030;
903 reg_l = 0x200;
904 reg_r = 0x600;
905 lev_left = SCALE(lev_left, 3) << 4;
906 lev_right = SCALE(lev_right, 3) << 4;
907 break;
909 case SOUND_MIXER_RECLEV:
910 mask = 0x000f;
911 reg_l = 0x300;
912 reg_r = 0x700;
913 lev_left = SCALE(lev_left, 10);
914 lev_right = SCALE(lev_right, 10);
915 break;
917 case SOUND_MIXER_LINE1:
918 if ((devc->recmask & SOUND_MASK_LINE1) == 0)
919 return;
920 mask = 0x003e;
921 reg_l = 0x000;
922 reg_r = 0x400;
923 lev_left = SCALE(lev_left, 31) << 1;
924 lev_right = SCALE(lev_right, 31) << 1;
925 break;
927 case SOUND_MIXER_PCM:
928 waveartist_cmd3(devc, WACMD_SET_LEVEL,
929 SCALE(lev_left, 32767),
930 SCALE(lev_right, 32767));
931 return;
933 case SOUND_MIXER_SYNTH:
934 waveartist_cmd3(devc, 0x0100 | WACMD_SET_LEVEL,
935 SCALE(lev_left, 32767),
936 SCALE(lev_right, 32767));
937 return;
939 default:
940 return;
943 /* read left setting */
944 vals[0] = reg_l + WACMD_GET_LEVEL;
945 waveartist_cmd(devc, 1, vals, 1, vals + 1);
947 /* read right setting */
948 vals[0] = reg_r + 0x30;
949 waveartist_cmd(devc, 1, vals, 1, vals + 2);
951 vals[1] = (vals[1] & ~mask) | (lev_left & mask);
952 vals[2] = (vals[2] & ~mask) | (lev_right & mask);
954 /* write left,right back */
955 vals[0] = WACMD_SET_MIXER;
956 waveartist_cmd(devc, 3, vals, 0, NULL);
959 static void
960 waveartist_select_input(wavnc_info *devc, unsigned int input)
962 unsigned int vals[3];
965 * Get reg 9
967 vals[0] = 0x0830;
968 waveartist_cmd(devc, 1, vals, 1, vals + 1);
971 * Get reg 10, only so that we can write it back.
973 vals[0] = 0x0930;
974 waveartist_cmd(devc, 1, vals, 1, vals + 2);
976 if (debug_flg & DEBUG_MIXER)
977 printk("RECSRC: old left: 0x%04X, old right: 0x%04X.\n",
978 vals[1] & 0x07, (vals[1] >> 3) & 0x07);
981 * kill current left/right mux input select
983 vals[1] &= ~0x03F;
985 switch (input) {
986 case SOUND_MASK_MIC:
988 * right=mic, left=mic
990 vals[1] |= 0x002D;
991 break;
993 case SOUND_MASK_LINE1:
995 * right=none, left=Aux1;
997 vals[1] |= 0x0004;
998 break;
1000 case SOUND_MASK_LINE:
1002 * right=Line, left=Line;
1004 vals[1] |= 0x0012;
1005 break;
1008 if (debug_flg & DEBUG_MIXER)
1009 printk("RECSRC %d: left=0x%04X, right=0x%04X.\n", input,
1010 vals[1] & 0x07, (vals[1] >> 3) & 0x07);
1013 * and finally - write the reg pair back....
1015 vals[0] = WACMD_SET_MIXER;
1017 waveartist_cmd(devc, 3, vals, 0, NULL);
1020 static int
1021 waveartist_mixer_set(wavnc_info *devc, int whichDev, unsigned int level)
1023 unsigned int lev_left = level & 0x007f;
1024 unsigned int lev_right = (level & 0x7f00) >> 8;
1025 int left, right, devmask;
1027 left = level & 0x7f;
1028 right = (level & 0x7f00) >> 8;
1030 if (debug_flg & DEBUG_MIXER)
1031 printk("wa_mixer_set(dev=%d, level=%X)\n",
1032 whichDev, level);
1034 switch (whichDev) {
1035 case SOUND_MIXER_VOLUME: /* master volume (0-7) */
1036 case SOUND_MIXER_LINE: /* external line (0-31) */
1037 case SOUND_MIXER_MIC: /* mono mic (0-3) */
1038 case SOUND_MIXER_RECLEV: /* recording level (0-7) */
1039 case SOUND_MIXER_LINE1: /* mono external aux1 (0-31) */
1040 case SOUND_MIXER_PCM: /* Waveartist PCM (0-32767) */
1041 case SOUND_MIXER_SYNTH: /* internal synth (0-31) */
1042 case SOUND_MIXER_IMIX: /* recording feedback */
1043 devc->levels[whichDev] = lev_left | lev_right << 8;
1044 waveartist_mixer_update(devc, whichDev);
1045 break;
1047 /* Select recording input source
1049 case SOUND_MIXER_RECSRC:
1050 devmask = level & devc->rec_devices;
1052 #ifdef CONFIG_ARCH_NETWINDER
1053 if (machine_is_netwinder())
1054 vnc_configure_mixer(devc);
1055 else
1056 #endif
1058 waveartist_select_input(devc, level);
1061 * if record monitoring is on, make sure the bit is set
1063 if (devc->levels[SOUND_MIXER_IMIX])
1064 waveartist_mixer_update(devc, SOUND_MIXER_IMIX);
1068 * do not save in "levels", return current setting
1070 return devc->recmask;
1072 default:
1073 return -EINVAL;
1076 return devc->levels[whichDev];
1079 static void
1080 waveartist_mixer_reset(wavnc_info *devc)
1082 int i;
1084 if (debug_flg & DEBUG_MIXER)
1085 printk("%s: mixer_reset\n", devc->hw.name);
1088 * reset mixer cmd
1090 waveartist_cmd1(devc, WACMD_RST_MIXER);
1093 * set input for ADC to come from 'quiet'
1094 * turn on default modes
1096 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x9800, 0xa836);
1099 * set mixer input select to none, RX filter gains 0 db
1101 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x4c00, 0x8c00);
1104 * set bit 0 reg 2 to 1 - unmute MonoOut
1106 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x2801, 0x6800);
1108 /* set default input device = internal mic
1109 * current recording device = none
1111 devc->recmask = 0;
1113 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1114 waveartist_mixer_update(devc, i);
1116 devc->supported_devices = SUPPORTED_MIXER_DEVICES;
1117 devc->rec_devices = POSSIBLE_RECORDING_DEVICES;
1119 if (machine_is_netwinder()) {
1120 devc->supported_devices |= SOUND_MASK_PHONEIN | SOUND_MASK_PHONEOUT;
1121 devc->rec_devices |= SOUND_MASK_PHONEIN;
1125 static int
1126 waveartist_mixer_ioctl(int dev, unsigned int cmd, caddr_t arg)
1128 wavnc_info *devc = (wavnc_info *)audio_devs[dev]->devc;
1129 int ret;
1131 #ifdef CONFIG_ARCH_NETWINDER
1132 if (machine_is_netwinder()) {
1133 ret = vnc_private_ioctl(dev, cmd, arg);
1134 if (ret != -ENOIOCTLCMD)
1135 return ret;
1137 #endif
1139 if (((cmd >> 8) & 0xff) == 'M') {
1140 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1141 int val;
1143 if (get_user(val, (int *)arg))
1144 return -EFAULT;
1146 return waveartist_mixer_set(devc, cmd & 0xff, val);
1147 } else {
1149 * Return parameters
1151 switch (cmd & 0xff) {
1152 case SOUND_MIXER_RECSRC:
1153 ret = devc->recmask;
1154 break;
1156 case SOUND_MIXER_DEVMASK:
1157 ret = devc->supported_devices;
1158 break;
1160 case SOUND_MIXER_STEREODEVS:
1161 ret = devc->supported_devices &
1162 ~(SOUND_MASK_SPEAKER|SOUND_MASK_IMIX);
1163 break;
1165 case SOUND_MIXER_RECMASK:
1166 ret = devc->rec_devices;
1167 break;
1169 case SOUND_MIXER_CAPS:
1170 ret = SOUND_CAP_EXCL_INPUT;
1171 break;
1173 default:
1174 if ((cmd & 0xff) < SOUND_MIXER_NRDEVICES)
1175 ret = devc->levels[cmd & 0xff];
1176 else
1177 return -EINVAL;
1180 return put_user(ret, (int *)arg) ? -EFAULT : 0;
1184 return -ENOIOCTLCMD;
1187 static struct mixer_operations waveartist_mixer_operations =
1189 "WaveArtist",
1190 "WaveArtist NetWinder",
1191 waveartist_mixer_ioctl
1194 static int
1195 waveartist_init(wavnc_info *devc)
1197 wavnc_port_info *portc;
1198 char rev[3], dev_name[64];
1199 int my_dev;
1201 if (waveartist_reset(devc))
1202 return -ENODEV;
1204 sprintf(dev_name, "%s (%s", devc->hw.name, devc->chip_name);
1206 if (waveartist_getrev(devc, rev)) {
1207 strcat(dev_name, " rev. ");
1208 strcat(dev_name, rev);
1210 strcat(dev_name, ")");
1212 conf_printf2(dev_name, devc->hw.io_base, devc->hw.irq,
1213 devc->hw.dma, devc->hw.dma2);
1215 portc = (wavnc_port_info *)kmalloc(sizeof(wavnc_port_info), GFP_KERNEL);
1216 if (portc == NULL)
1217 goto nomem;
1219 memset(portc, 0, sizeof(wavnc_port_info));
1221 my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION, dev_name,
1222 &waveartist_audio_driver, sizeof(struct audio_driver),
1223 devc->audio_flags, AFMT_U8 | AFMT_S16_LE | AFMT_S8,
1224 devc, devc->hw.dma, devc->hw.dma2);
1226 if (my_dev < 0)
1227 goto free;
1229 audio_devs[my_dev]->portc = portc;
1231 waveartist_mixer_reset(devc);
1234 * clear any pending interrupt
1236 waveartist_iack(devc);
1238 if (request_irq(devc->hw.irq, waveartist_intr, 0, devc->hw.name, devc) < 0) {
1239 printk(KERN_ERR "%s: IRQ %d in use\n",
1240 devc->hw.name, devc->hw.irq);
1241 goto uninstall;
1244 if (sound_alloc_dma(devc->hw.dma, devc->hw.name)) {
1245 printk(KERN_ERR "%s: Can't allocate DMA%d\n",
1246 devc->hw.name, devc->hw.dma);
1247 goto uninstall_irq;
1250 if (devc->hw.dma != devc->hw.dma2 && devc->hw.dma2 != NO_DMA)
1251 if (sound_alloc_dma(devc->hw.dma2, devc->hw.name)) {
1252 printk(KERN_ERR "%s: can't allocate DMA%d\n",
1253 devc->hw.name, devc->hw.dma2);
1254 goto uninstall_dma;
1257 waveartist_set_ctlr(&devc->hw, 0, DMA1_IE | DMA0_IE);
1259 audio_devs[my_dev]->mixer_dev =
1260 sound_install_mixer(MIXER_DRIVER_VERSION,
1261 dev_name,
1262 &waveartist_mixer_operations,
1263 sizeof(struct mixer_operations),
1264 devc);
1266 return my_dev;
1268 uninstall_dma:
1269 sound_free_dma(devc->hw.dma);
1271 uninstall_irq:
1272 free_irq(devc->hw.irq, devc);
1274 uninstall:
1275 sound_unload_audiodev(my_dev);
1277 free:
1278 kfree(portc);
1280 nomem:
1281 return -1;
1284 static int __init probe_waveartist(struct address_info *hw_config)
1286 wavnc_info *devc = &adev_info[nr_waveartist_devs];
1288 if (nr_waveartist_devs >= MAX_AUDIO_DEV) {
1289 printk(KERN_WARNING "waveartist: too many audio devices\n");
1290 return 0;
1293 if (check_region(hw_config->io_base, 15)) {
1294 printk(KERN_WARNING "WaveArtist: I/O port conflict\n");
1295 return 0;
1298 if (hw_config->irq > _ISA_IRQ(15) || hw_config->irq < _ISA_IRQ(0)) {
1299 printk(KERN_WARNING "WaveArtist: Bad IRQ %d\n",
1300 hw_config->irq);
1301 return 0;
1304 if (hw_config->dma != _ISA_DMA(3)) {
1305 printk(KERN_WARNING "WaveArtist: Bad DMA %d\n",
1306 hw_config->dma);
1307 return 0;
1310 hw_config->name = "WaveArtist";
1311 devc->hw = *hw_config;
1312 devc->open_mode = 0;
1313 devc->chip_name = "RWA-010";
1315 return 1;
1318 static void __init attach_waveartist(struct address_info *hw)
1320 wavnc_info *devc = &adev_info[nr_waveartist_devs];
1323 * NOTE! If irq < 0, there is another driver which has allocated the
1324 * IRQ so that this driver doesn't need to allocate/deallocate it.
1325 * The actually used IRQ is ABS(irq).
1327 devc->hw = *hw;
1328 devc->hw.irq = (hw->irq > 0) ? hw->irq : 0;
1329 devc->open_mode = 0;
1330 devc->playback_dev = 0;
1331 devc->record_dev = 0;
1332 devc->audio_flags = DMA_AUTOMODE;
1333 devc->levels = levels;
1335 if (hw->dma != hw->dma2 && hw->dma2 != NO_DMA)
1336 devc->audio_flags |= DMA_DUPLEX;
1338 request_region(hw->io_base, 15, devc->hw.name);
1340 devc->dev_no = waveartist_init(devc);
1342 if (devc->dev_no < 0)
1343 release_region(hw->io_base, 15);
1344 else {
1345 #ifdef CONFIG_ARCH_NETWINDER
1346 if (machine_is_netwinder()) {
1347 init_timer(&vnc_timer);
1348 vnc_timer.function = vnc_slider_tick;
1349 vnc_timer.expires = jiffies;
1350 vnc_timer.data = nr_waveartist_devs;
1351 add_timer(&vnc_timer);
1353 vnc_configure_mixer(devc);
1355 #endif
1356 nr_waveartist_devs += 1;
1360 static void __exit unload_waveartist(struct address_info *hw)
1362 wavnc_info *devc = NULL;
1363 int i;
1365 for (i = 0; i < nr_waveartist_devs; i++)
1366 if (hw->io_base == adev_info[i].hw.io_base) {
1367 devc = adev_info + i;
1368 break;
1371 if (devc != NULL) {
1372 int mixer;
1374 #ifdef CONFIG_ARCH_NETWINDER
1375 if (machine_is_netwinder())
1376 del_timer(&vnc_timer);
1377 #endif
1379 release_region(devc->hw.io_base, 15);
1381 waveartist_set_ctlr(&devc->hw, DMA1_IE|DMA0_IE, 0);
1383 if (devc->hw.irq >= 0)
1384 free_irq(devc->hw.irq, devc);
1386 sound_free_dma(devc->hw.dma);
1388 if (devc->hw.dma != devc->hw.dma2 &&
1389 devc->hw.dma2 != NO_DMA)
1390 sound_free_dma(devc->hw.dma2);
1392 mixer = audio_devs[devc->dev_no]->mixer_dev;
1394 if (mixer >= 0)
1395 sound_unload_mixerdev(mixer);
1397 if (devc->dev_no >= 0)
1398 sound_unload_audiodev(devc->dev_no);
1400 nr_waveartist_devs -= 1;
1402 for (; i < nr_waveartist_devs; i++)
1403 adev_info[i] = adev_info[i + 1];
1404 } else
1405 printk(KERN_WARNING "waveartist: can't find device "
1406 "to unload\n");
1410 * Rebel.com Netwinder specifics...
1413 #define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
1415 #define MIXER_PRIVATE3_RESET 0x53570000
1416 #define MIXER_PRIVATE3_READ 0x53570001
1417 #define MIXER_PRIVATE3_WRITE 0x53570002
1419 #define VNC_MUTE_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
1420 #define VNC_MUTE_LINE_OUT 0x10
1421 #define VNC_PHONE_DETECT 0x20
1422 #define VNC_HANDSET_DETECT 0x40
1423 #define VNC_DISABLE_AUTOSWITCH 0x80
1425 extern spinlock_t gpio_lock;
1427 static inline void
1428 vnc_update_spkr_mute(wavnc_info *devc)
1430 unsigned long flags;
1432 spin_lock_irqsave(&gpio_lock, flags);
1433 cpld_modify(CPLD_UNMUTE, devc->spkr_mute_state ? 0 : CPLD_UNMUTE);
1434 spin_unlock_irqrestore(&gpio_lock, flags);
1437 static void
1438 vnc_mute_lout(wavnc_info *devc, int mute)
1442 static int
1443 vnc_volume_slider(wavnc_info *devc)
1445 static signed int old_slider_volume;
1446 unsigned long flags;
1447 signed int volume = 255;
1449 *CSR_TIMER1_LOAD = 0x00ffffff;
1451 save_flags(flags);
1452 cli();
1454 outb(0xFF, 0x201);
1455 *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV1;
1457 while (volume && (inb(0x201) & 0x01))
1458 volume--;
1460 *CSR_TIMER1_CNTL = 0;
1462 restore_flags(flags);
1464 volume = 0x00ffffff - *CSR_TIMER1_VALUE;
1467 #ifndef REVERSE
1468 volume = 150 - (volume >> 5);
1469 #else
1470 volume = (volume >> 6) - 25;
1471 #endif
1473 if (volume < 0)
1474 volume = 0;
1476 if (volume > 100)
1477 volume = 100;
1480 * slider quite often reads +-8, so debounce this random noise
1482 if (abs(volume - old_slider_volume) > 7) {
1483 old_slider_volume = volume;
1485 if (debug_flg & DEBUG_MIXER)
1486 printk(KERN_DEBUG "Slider volume: %d.\n", volume);
1489 return old_slider_volume;
1492 static void
1493 vnc_configure_mixer(wavnc_info *devc)
1495 u_int vals[3];
1497 if (!devc->no_autoselect) {
1498 if (devc->handset_detect) {
1499 devc->recmask = SOUND_MASK_LINE1;
1500 devc->spkr_mute_state = devc->line_mute_state = 1;
1501 } else if (devc->telephone_detect) {
1502 devc->recmask = SOUND_MASK_PHONEIN;
1503 devc->spkr_mute_state = devc->line_mute_state = 1;
1504 } else {
1505 /* unless someone has asked for LINE-IN,
1506 * we default to MIC
1508 if ((devc->recmask & SOUND_MASK_LINE) == 0)
1509 devc->recmask = SOUND_MASK_MIC;
1510 devc->spkr_mute_state = devc->line_mute_state = 0;
1512 vnc_update_spkr_mute(devc);
1513 vnc_mute_lout(devc, devc->spkr_mute_state);
1516 /* Ok. At this point, we have done the autoswitch logic, or we
1517 * have had a command from an ioctl. We have a valid devc->recmask.
1518 * Now we have to connect up the hardware to reflect the recmask.
1520 vals[1] = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x800);
1521 vals[2] = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x900);
1523 vals[1] &= ~0x3f;
1525 switch(devc->recmask) {
1526 case SOUND_MASK_MIC: /* builtin mic */
1527 waveartist_cmd1(devc, WACMD_SET_MONO | 0x100); /* right */
1528 vals[1] |= 0x28;
1529 break;
1531 case SOUND_MASK_LINE1: /* out handset */
1532 waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
1533 vals[1] |= 0x05;
1534 break;
1536 case SOUND_MASK_PHONEIN: /* our telephone mic */
1537 waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
1538 vals[1] |= 0x04;
1539 break;
1541 case SOUND_MASK_LINE: /* stereo line in */
1542 vals[1] |= 12;
1543 break;
1545 default:
1546 return;
1549 vals[0] = WACMD_SET_MIXER;
1550 waveartist_cmd(devc, 3, vals, 0, NULL);
1552 waveartist_mixer_update(devc, SOUND_MIXER_IMIX);
1555 static int
1556 vnc_slider(wavnc_info *devc)
1558 signed int slider_volume;
1559 unsigned int temp, old_hs, old_td;
1562 * read the "buttons" state.
1563 * Bit 4 = handset present,
1564 * Bit 5 = offhook
1566 temp = inb(0x201) & 0x30;
1568 old_hs = devc->handset_detect;
1569 old_td = devc->telephone_detect;
1571 devc->handset_detect = !(temp & 0x10);
1572 devc->telephone_detect = !!(temp & 0x20);
1574 if (!devc->no_autoselect &&
1575 (old_hs != devc->handset_detect ||
1576 old_td != devc->telephone_detect))
1577 vnc_configure_mixer(devc);
1579 slider_volume = vnc_volume_slider(devc);
1582 * If we're using software controlled volume, and
1583 * the slider moves by more than 20%, then we
1584 * switch back to slider controlled volume.
1586 if (abs(devc->slider_vol - slider_volume) > 20)
1587 devc->use_slider = 1;
1590 * use only left channel
1592 temp = levels[SOUND_MIXER_VOLUME] & 0xFF;
1594 if (slider_volume != temp && devc->use_slider) {
1595 devc->slider_vol = slider_volume;
1597 waveartist_mixer_set(devc, SOUND_MIXER_VOLUME,
1598 slider_volume | slider_volume << 8);
1600 return 1;
1603 return 0;
1606 static void
1607 vnc_slider_tick(unsigned long data)
1609 int next_timeout;
1611 if (vnc_slider(adev_info + data))
1612 next_timeout = 5; // mixer reported change
1613 else
1614 next_timeout = VNC_TIMER_PERIOD;
1616 mod_timer(&vnc_timer, jiffies + next_timeout);
1619 static int
1620 vnc_private_ioctl(int dev, unsigned int cmd, caddr_t arg)
1622 wavnc_info *devc = (wavnc_info *)audio_devs[dev]->devc;
1623 int val;
1625 switch (cmd) {
1626 case SOUND_MIXER_PRIVATE1:
1628 u_int prev_spkr_mute, prev_line_mute, prev_auto_state;
1629 int val;
1631 get_user_ret(val, (int *)arg, -EFAULT);
1633 /* check if parameter is logical */
1634 if (val & ~(VNC_MUTE_INTERNAL_SPKR |
1635 VNC_MUTE_LINE_OUT |
1636 VNC_DISABLE_AUTOSWITCH))
1637 return -EINVAL;
1639 prev_auto_state = devc->no_autoselect;
1640 prev_spkr_mute = devc->spkr_mute_state;
1641 prev_line_mute = devc->line_mute_state;
1643 devc->no_autoselect = (val & VNC_DISABLE_AUTOSWITCH) ? 1 : 0;
1644 devc->spkr_mute_state = (val & VNC_MUTE_INTERNAL_SPKR) ? 1 : 0;
1645 devc->line_mute_state = (val & VNC_MUTE_LINE_OUT) ? 1 : 0;
1647 if (prev_spkr_mute != devc->spkr_mute_state)
1648 vnc_update_spkr_mute(devc);
1650 if (prev_line_mute != devc->line_mute_state)
1651 vnc_mute_lout(devc, devc->line_mute_state);
1653 if (prev_auto_state != devc->no_autoselect)
1654 vnc_configure_mixer(devc);
1656 return 0;
1659 case SOUND_MIXER_PRIVATE2:
1660 get_user_ret(val, (int *)arg, -EFAULT);
1662 switch (val) {
1663 #define VNC_SOUND_PAUSE 0x53 //to pause the DSP
1664 #define VNC_SOUND_RESUME 0x57 //to unpause the DSP
1665 case VNC_SOUND_PAUSE:
1666 waveartist_cmd1(devc, 0x16);
1667 break;
1669 case VNC_SOUND_RESUME:
1670 waveartist_cmd1(devc, 0x18);
1671 break;
1673 default:
1674 return -EINVAL;
1676 return 0;
1678 /* private ioctl to allow bulk access to waveartist */
1679 case SOUND_MIXER_PRIVATE3:
1681 unsigned long flags;
1682 int mixer_reg[15], i, val;
1684 get_user_ret(val, (int *)arg, -EFAULT);
1685 copy_from_user_ret(mixer_reg, (void *)val, sizeof(mixer_reg), -EFAULT);
1687 switch (mixer_reg[14]) {
1688 case MIXER_PRIVATE3_RESET:
1689 waveartist_mixer_reset(devc);
1690 break;
1692 case MIXER_PRIVATE3_WRITE:
1693 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[0], mixer_reg[4]);
1694 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[1], mixer_reg[5]);
1695 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[2], mixer_reg[6]);
1696 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[3], mixer_reg[7]);
1697 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[8], mixer_reg[9]);
1699 waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[10], mixer_reg[11]);
1700 waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[12], mixer_reg[13]);
1701 break;
1703 case MIXER_PRIVATE3_READ:
1704 spin_lock_irqsave(&waveartist_lock, flags);
1706 for (i = 0x30; i < 14 << 8; i += 1 << 8)
1707 waveartist_cmd(devc, 1, &i, 1, mixer_reg + (i >> 8));
1709 spin_unlock_irqrestore(&waveartist_lock, flags);
1711 copy_to_user_ret((void *)val, mixer_reg, sizeof(mixer_reg), -EFAULT);
1712 break;
1714 default:
1715 return -EINVAL;
1717 return 0;
1720 /* read back the state from PRIVATE1 */
1721 case SOUND_MIXER_PRIVATE4:
1722 val = (devc->spkr_mute_state ? VNC_MUTE_INTERNAL_SPKR : 0) |
1723 (devc->line_mute_state ? VNC_MUTE_LINE_OUT : 0) |
1724 (devc->handset_detect ? VNC_HANDSET_DETECT : 0) |
1725 (devc->telephone_detect ? VNC_PHONE_DETECT : 0) |
1726 (devc->no_autoselect ? VNC_DISABLE_AUTOSWITCH : 0);
1728 return put_user(val, (int *)arg) ? -EFAULT : 0;
1731 if (((cmd >> 8) & 0xff) == 'M') {
1732 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1734 * special case for master volume: if we
1735 * received this call - switch from hw
1736 * volume control to a software volume
1737 * control, till the hw volume is modified
1738 * to signal that user wants to be back in
1739 * hardware...
1741 if ((cmd & 0xff) == SOUND_MIXER_VOLUME)
1742 devc->use_slider = 0;
1743 } else if ((cmd & 0xff) == SOUND_MIXER_STEREODEVS) {
1744 val = devc->supported_devices &
1745 ~(SOUND_MASK_IMIX |
1746 SOUND_MASK_MIC |
1747 SOUND_MASK_LINE1 |
1748 SOUND_MASK_PHONEIN |
1749 SOUND_MASK_PHONEOUT);
1750 return put_user(val, (int *)arg) ? -EFAULT : 0;
1754 return -ENOIOCTLCMD;
1757 static struct address_info cfg;
1759 static int attached;
1761 static int __initdata io;
1762 static int __initdata irq;
1763 static int __initdata dma;
1764 static int __initdata dma2;
1767 MODULE_PARM(io, "i"); /* IO base */
1768 MODULE_PARM(irq, "i"); /* IRQ */
1769 MODULE_PARM(dma, "i"); /* DMA */
1770 MODULE_PARM(dma2, "i"); /* DMA2 */
1772 static int __init init_waveartist(void)
1774 if (!io && machine_is_netwinder()) {
1776 * The NetWinder WaveArtist is at a fixed address.
1777 * If the user does not supply an address, use the
1778 * well-known parameters.
1780 io = 0x250;
1781 irq = 12;
1782 dma = 3;
1783 dma2 = 7;
1786 cfg.io_base = io;
1787 cfg.irq = irq;
1788 cfg.dma = dma;
1789 cfg.dma2 = dma2;
1791 if (!probe_waveartist(&cfg))
1792 return -ENODEV;
1794 attach_waveartist(&cfg);
1795 attached = 1;
1797 SOUND_LOCK;
1798 return 0;
1801 static void __exit cleanup_waveartist(void)
1803 if (attached) {
1804 SOUND_LOCK_END;
1805 unload_waveartist(&cfg);
1809 module_init(init_waveartist);
1810 module_exit(cleanup_waveartist);
1812 #ifndef MODULE
1813 static int __init setup_waveartist(char *str)
1815 /* io, irq, dma, dma2 */
1816 int ints[5];
1818 str = get_options(str, ARRAY_SIZE(ints), ints);
1820 io = ints[1];
1821 irq = ints[2];
1822 dma = ints[3];
1823 dma16 = ints[4];
1825 return 1;
1827 __setup("waveartist=", setup_waveartist);
1828 #endif