* better
[mascara-docs.git] / i386 / linux-2.3.21 / drivers / sound / waveartist.c
blob85a9efaec91ac43223414ef860f50c85c257dd08
1 /*
2 * drivers/sound/waveartist.c
4 * The low level driver for the RWA010 Rockwell Wave Artist
5 * codec chip used in the Corel Computer NetWinder.
7 * Cleaned up and integrated into 2.1 by Russell King (rmk@arm.linux.org.uk)
8 */
11 * Copyright (C) by Corel Computer 1998
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 #define DEB(x)
33 #define DDB(x)
34 #define DEB1(x)
36 #include <linux/module.h>
37 #include <linux/config.h>
38 #include <linux/sched.h>
39 #include <linux/interrupt.h>
40 #include <linux/delay.h>
41 #include <linux/smp.h>
43 #include <asm/dec21285.h>
44 #include <asm/hardware.h>
46 #include "soundmodule.h"
47 #include "sound_config.h"
48 #include "waveartist.h"
50 #ifndef _ISA_DMA
51 #define _ISA_DMA(x) (x)
52 #endif
53 #ifndef _ISA_IRQ
54 #define _ISA_IRQ(x) (x)
55 #endif
57 #define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
59 #define MIXER_PRIVATE3_RESET 0x53570000
60 #define MIXER_PRIVATE3_READ 0x53570001
61 #define MIXER_PRIVATE3_WRITE 0x53570002
63 #define VNC_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
64 #define VNC_INTERNAL_MIC 0x10 //the hw internal/handset mic bit
66 /* Use RECSRC = speaker to mark the internal microphone
68 * Some cheating involved here: there is no way to relay
69 * to the system, which microphone in in use
70 * (left = handset, or right = internal)
72 * So while I do not flag SPEAKER in the Recording Devices
73 * Mask, when on internal
75 * mike - I set the speaker bit hi. Some mixers can be
76 * confused a bit...
79 #define POSSIBLE_RECORDING_DEVICES (SOUND_MASK_LINE |\
80 SOUND_MASK_MIC |\
81 SOUND_MASK_LINE1) //Line1 = analog phone
83 #define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH |\
84 SOUND_MASK_PCM |\
85 SOUND_MASK_LINE |\
86 SOUND_MASK_MIC | \
87 SOUND_MASK_LINE1 |\
88 SOUND_MASK_RECLEV |\
89 SOUND_MASK_VOLUME)
91 static unsigned short levels[SOUND_MIXER_NRDEVICES] = {
92 0x5555, /* Master Volume */
93 0x0000, /* Bass */
94 0x0000, /* Treble */
95 0x5555, /* Synth (FM) */
96 0x4b4b, /* PCM */
97 0x0000, /* PC Speaker */
98 0x0000, /* Ext Line */
99 0x0000, /* Mic */
100 0x0000, /* CD */
101 0x0000, /* Recording monitor */
102 0x0000, /* SB PCM (ALT PCM) */
103 0x0000, /* Recording level */
104 0x0000, /* Input gain */
105 0x0000, /* Output gain */
106 0x0000, /* Line1 (Aux1) */
107 0x0000, /* Line2 (Aux2) */
108 0x0000, /* Line3 (Aux3) */
109 0x0000, /* Digital1 */
110 0x0000, /* Digital2 */
111 0x0000, /* Digital3 */
112 0x0000, /* Phone In */
113 0x0000, /* Phone Out */
114 0x0000, /* Video */
115 0x0000, /* Radio */
116 0x0000 /* Monitor */
119 typedef struct {
120 struct address_info hw; /* hardware */
121 char *chip_name;
123 int xfer_count;
124 int audio_mode;
125 int open_mode;
126 int audio_flags;
127 int record_dev;
128 int playback_dev;
129 int dev_no;
131 /* Mixer parameters */
132 unsigned short *levels;
133 int handset_state;
134 signed int slider_vol; /* hardware slider volume */
135 int recmask; /* currently enabled recording device! */
136 int supported_devices; /* SUPPORTED_MIXER_DEVICES */
137 int rec_devices; /* POSSIBLE_RECORDING_DEVICES */
138 int handset_mute_sw :1;/* 1 - handset controlled in sw */
139 int use_slider :1;/* use slider setting for o/p vol */
140 int mute_state :1;
141 } wavnc_info;
143 typedef struct wavnc_port_info {
144 int open_mode;
145 int speed;
146 int channels;
147 int audio_format;
148 } wavnc_port_info;
150 static int nr_waveartist_devs;
151 static wavnc_info adev_info[MAX_AUDIO_DEV];
153 static int waveartist_mixer_set(wavnc_info *devc, int whichDev, unsigned int level);
156 * Corel Netwinder specifics...
158 static struct timer_list vnc_timer;
159 extern spinlock_t gpio_lock;
161 static void
162 vnc_mute(wavnc_info *devc, int mute)
164 unsigned long flags;
166 spin_lock_irqsave(&gpio_lock, flags);
167 cpld_modify(CPLD_UNMUTE, mute ? 0 : CPLD_UNMUTE);
168 spin_unlock_irqrestore(&gpio_lock, flags);
170 devc->mute_state = mute;
173 static int
174 vnc_volume_slider(wavnc_info *devc)
176 static signed int old_slider_volume;
177 unsigned long flags;
178 signed int volume = 255;
180 *CSR_TIMER1_LOAD = 0x00ffffff;
182 save_flags(flags);
183 cli();
185 outb(0xFF, 0x201);
186 *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV1;
188 while (volume && (inb(0x201) & 0x01))
189 volume--;
191 *CSR_TIMER1_CNTL = 0;
193 restore_flags(flags);
195 volume = 0x00ffffff - *CSR_TIMER1_VALUE;
198 #ifndef REVERSE
199 volume = 150 - (volume >> 5);
200 #else
201 volume = (volume >> 6) - 25;
202 #endif
204 if (volume < 0)
205 volume = 0;
207 if (volume > 100)
208 volume = 100;
211 * slider quite often reads +-8, so debounce this random noise
213 if ((volume - old_slider_volume) > 7 ||
214 (old_slider_volume - volume) > 7) {
215 old_slider_volume = volume;
217 DEB(printk("Slider volume: %d.\n", old_slider_volume));
220 return old_slider_volume;
223 static int
224 vnc_slider(wavnc_info *devc)
226 signed int slider_volume;
227 unsigned int temp;
230 * read the "buttons" state.
231 * Bit 4 = handset present,
232 * Bit 5 = offhook
234 // the state should be "querable" via a private IOCTL call
235 temp = inb(0x201) & 0x30;
237 if (!devc->handset_mute_sw &&
238 (temp ^ devc->handset_state) & VNC_INTERNAL_MIC) {
239 devc->handset_state = temp;
240 devc->handset_mute_sw = 0;
242 vnc_mute(devc, (temp & VNC_INTERNAL_MIC) ? 1 : 0);
245 slider_volume = vnc_volume_slider(devc);
248 * If we're using software controlled volume, and
249 * the slider moves by more than 20%, then we
250 * switch back to slider controlled volume.
252 if (devc->slider_vol > slider_volume) {
253 if (devc->slider_vol - slider_volume > 20)
254 devc->use_slider = 1;
255 } else {
256 if (slider_volume - devc->slider_vol > 20)
257 devc->use_slider = 1;
261 * use only left channel
263 temp = levels[SOUND_MIXER_VOLUME] & 0xFF;
265 if (slider_volume != temp && devc->use_slider) {
266 devc->slider_vol = slider_volume;
268 waveartist_mixer_set(devc, SOUND_MIXER_VOLUME,
269 slider_volume | slider_volume << 8);
271 return 1;
274 return 0;
277 static void
278 vnc_slider_tick(unsigned long data)
280 int next_timeout;
282 if (vnc_slider(adev_info + data))
283 next_timeout = 5; // mixer reported change
284 else
285 next_timeout = VNC_TIMER_PERIOD;
287 mod_timer(&vnc_timer, jiffies + next_timeout);
290 static int
291 vnc_private_ioctl(int dev, unsigned int cmd, caddr_t arg)
293 wavnc_info *devc = (wavnc_info *)audio_devs[dev]->devc;
294 int val, temp;
296 if (cmd == SOUND_MIXER_PRIVATE1) {
298 * Use this call to override the automatic handset
299 * behaviour - ignore handset.
300 * bit 7 = total control over handset - do not
301 * to plug/unplug
302 * bit 4 = internal mic
303 * bit 0 = mute internal speaker
305 if (get_user(val, (int *)arg))
306 return -EFAULT;
308 devc->handset_mute_sw = val;
310 temp = val & VNC_INTERNAL_SPKR;
311 if (devc->mute_state != temp)
312 vnc_mute(devc, temp);
314 devc->handset_state = val & VNC_INTERNAL_MIC;
315 waveartist_mixer_set(devc, SOUND_MIXER_RECSRC, SOUND_MASK_MIC);
316 return 0;
318 #if 0
319 if (cmd == SOUND_MIXER_PRIVATE2) {
320 #define VNC_SOUND_PAUSE 0x53 //to pause the DSP
321 #define VNC_SOUND_RESUME 0x57 //to unpause the DSP
322 int val;
324 val = *(int *) arg;
326 printk("MIXER_PRIVATE2: passed parameter = 0x%X.\n",val);
328 if (val == VNC_SOUND_PAUSE) {
329 wa_sendcmd(0x16); //PAUSE the ADC
330 } else if (val == VNC_SOUND_RESUME) {
331 wa_sendcmd(0x18); //RESUME the ADC
332 } else {
333 return -EINVAL; //invalid parameters...
335 return 0;
338 if (cmd == SOUND_MIXER_PRIVATE3) {
339 long unsigned flags;
340 int mixer_reg[15]; //reg 14 is actually a command: read,write,reset
342 int val;
343 int i;
345 val = *(int *) arg;
347 if (verify_area(VERIFY_READ, (void *) val, sizeof(mixer_reg) == -EFAULT))
348 return (-EFAULT);
350 memcpy_fromfs(&mixer_reg, (void *) val, sizeof(mixer_reg));
352 if (mixer_reg[0x0E] == MIXER_PRIVATE3_RESET) { //reset command??
353 wavnc_mixer_reset(devc);
354 return (0);
355 } else if (mixer_reg[0x0E] == MIXER_PRIVATE3_WRITE) { //write command??
356 // printk("WaveArtist Mixer: Private write command.\n");
358 wa_sendcmd(0x32); //Pair1 - word 1 and 5
359 wa_sendcmd(mixer_reg[0]);
360 wa_sendcmd(mixer_reg[4]);
362 wa_sendcmd(0x32); //Pair2 - word 2 and 6
363 wa_sendcmd(mixer_reg[1]);
364 wa_sendcmd(mixer_reg[5]);
366 wa_sendcmd(0x32); //Pair3 - word 3 and 7
367 wa_sendcmd(mixer_reg[2]);
368 wa_sendcmd(mixer_reg[6]);
370 wa_sendcmd(0x32); //Pair4 - word 4 and 8
371 wa_sendcmd(mixer_reg[3]);
372 wa_sendcmd(mixer_reg[7]);
374 wa_sendcmd(0x32); //Pair5 - word 9 and 10
375 wa_sendcmd(mixer_reg[8]);
376 wa_sendcmd(mixer_reg[9]);
378 wa_sendcmd(0x0031); //set left and right PCM
379 wa_sendcmd(mixer_reg[0x0A]);
380 wa_sendcmd(mixer_reg[0x0B]);
382 wa_sendcmd(0x0131); //set left and right FM
383 wa_sendcmd(mixer_reg[0x0C]);
384 wa_sendcmd(mixer_reg[0x0D]);
386 return 0;
387 } else if (mixer_reg[0x0E] == MIXER_PRIVATE3_READ) { //read command?
388 // printk("WaveArtist Mixer: Private read command.\n");
390 //first read all current values...
391 save_flags(flags);
392 cli();
394 for (i = 0; i < 14; i++) {
395 wa_sendcmd((i << 8) + 0x30); // get ready for command nn30H
397 while (!(inb(STATR) & CMD_RF)) {
398 }; //wait for response ready...
400 mixer_reg[i] = inw(CMDR);
402 restore_flags(flags);
404 if (verify_area(VERIFY_WRITE, (void *) val, sizeof(mixer_reg) == -EFAULT))
405 return (-EFAULT);
407 memcpy_tofs((void *) val, &mixer_reg, sizeof(mixer_reg));
408 return 0;
409 } else
410 return -EINVAL;
412 #endif
413 return -EINVAL;
416 static inline void
417 waveartist_set_ctlr(struct address_info *hw, unsigned char clear, unsigned char set)
419 unsigned int ctlr_port = hw->io_base + CTLR;
421 clear = ~clear & inb(ctlr_port);
423 outb(clear | set, ctlr_port);
426 /* Toggle IRQ acknowledge line
428 static inline void
429 waveartist_iack(wavnc_info *devc)
431 unsigned int ctlr_port = devc->hw.io_base + CTLR;
432 int old_ctlr;
434 old_ctlr = inb(ctlr_port) & ~IRQ_ACK;
436 outb(old_ctlr | IRQ_ACK, ctlr_port);
437 outb(old_ctlr, ctlr_port);
440 static inline int
441 waveartist_sleep(int timeout_ms)
443 unsigned int timeout = timeout_ms * 10 * HZ / 100;
445 do {
446 current->state = TASK_INTERRUPTIBLE;
447 timeout = schedule_timeout(timeout);
448 } while (timeout);
450 return 0;
453 static int
454 waveartist_reset(wavnc_info *devc)
456 struct address_info *hw = &devc->hw;
457 unsigned int timeout, res = -1;
459 waveartist_set_ctlr(hw, -1, RESET);
460 waveartist_sleep(2);
461 waveartist_set_ctlr(hw, RESET, 0);
463 timeout = 500;
464 do {
465 mdelay(2);
467 if (inb(hw->io_base + STATR) & CMD_RF) {
468 res = inw(hw->io_base + CMDR);
469 if (res == 0x55aa)
470 break;
472 } while (timeout--);
474 if (timeout == 0) {
475 printk("WaveArtist: reset timeout ");
476 if (res != (unsigned int)-1)
477 printk("(res=%04X)", res);
478 printk("\n");
479 return 1;
481 return 0;
484 static int
485 waveartist_cmd(wavnc_info *devc,
486 int nr_cmd, unsigned int *cmd,
487 int nr_resp, unsigned int *resp)
489 unsigned int io_base = devc->hw.io_base;
490 unsigned int timed_out = 0;
491 unsigned int i;
493 if (debug_flg & DEBUG_CMD) {
494 printk("waveartist_cmd: cmd=");
496 for (i = 0; i < nr_cmd; i++)
497 printk("%04X ", cmd[i]);
499 printk("\n");
502 if (inb(io_base + STATR) & CMD_RF) {
503 int old_data;
505 /* flush the port
508 old_data = inw(io_base + CMDR);
510 if (debug_flg & DEBUG_CMD)
511 printk("flushed %04X...", old_data);
513 udelay(10);
516 for (i = 0; !timed_out && i < nr_cmd; i++) {
517 int count;
519 for (count = 5000; count; count--)
520 if (inb(io_base + STATR) & CMD_WE)
521 break;
523 if (!count)
524 timed_out = 1;
525 else
526 outw(cmd[i], io_base + CMDR);
529 for (i = 0; !timed_out && i < nr_resp; i++) {
530 int count;
532 for (count = 5000; count; count--)
533 if (inb(io_base + STATR) & CMD_RF)
534 break;
536 if (!count)
537 timed_out = 1;
538 else
539 resp[i] = inw(io_base + CMDR);
542 if (debug_flg & DEBUG_CMD) {
543 if (!timed_out) {
544 printk("waveartist_cmd: resp=");
546 for (i = 0; i < nr_resp; i++)
547 printk("%04X ", resp[i]);
549 printk("\n");
550 } else
551 printk("waveartist_cmd: timed out\n");
554 return timed_out ? 1 : 0;
557 static inline int
558 waveartist_cmd2(wavnc_info *devc, unsigned int cmd, unsigned int arg)
560 unsigned int vals[2];
562 vals[0] = cmd;
563 vals[1] = arg;
565 waveartist_cmd(devc, 2, vals, 1, vals);
567 return 0;
570 static inline int
571 waveartist_cmd3(wavnc_info *devc, unsigned int cmd,
572 unsigned int arg1, unsigned int arg2)
574 unsigned int vals[3];
576 vals[0] = cmd;
577 vals[1] = arg1;
578 vals[2] = arg2;
580 return waveartist_cmd(devc, 3, vals, 0, NULL);
583 static int
584 waveartist_sendcmd(struct address_info *hw, unsigned int cmd)
586 int count;
588 if (debug_flg & DEBUG_CMD)
589 printk("waveartist_sendcmd: cmd=0x%04X...", cmd);
591 udelay(10);
593 if (inb(hw->io_base + STATR) & CMD_RF) {
595 * flush the port
597 count = inw(hw->io_base + CMDR);
599 udelay(10);
601 if (debug_flg & DEBUG_CMD)
602 printk(" flushed %04X...", count);
606 * preset timeout at 5000 loops
608 count = 5000;
610 while (count --)
611 if (inb(hw->io_base + STATR) & CMD_WE) {
612 /* wait till CMD_WE is high
613 * then output the command
615 outw(cmd, hw->io_base + CMDR);
616 break;
619 /* ready BEFORE timeout?
621 if (debug_flg & DEBUG_CMD)
622 printk(" %s\n", count ? "Done OK." : "Error!");
624 udelay(10);
626 return count ? 0 : 1;
629 static int
630 waveartist_getrev(struct address_info *hw, char *rev)
632 int temp;
634 waveartist_sendcmd(hw, 0);
635 udelay(20);
636 temp = inw(hw->io_base + CMDR);
637 udelay(20);
638 inw(hw->io_base + CMDR); // discard second word == 0
640 rev[0] = temp >> 8;
641 rev[1] = temp & 255;
642 rev[2] = '\0';
644 return temp;
647 inline void
648 waveartist_mute(wavnc_info *devc, int mute)
652 static void waveartist_halt_output(int dev);
653 static void waveartist_halt_input(int dev);
654 static void waveartist_halt(int dev);
655 static void waveartist_trigger(int dev, int state);
657 static int
658 waveartist_open(int dev, int mode)
660 wavnc_info *devc;
661 wavnc_port_info *portc;
662 unsigned long flags;
664 if (dev < 0 || dev >= num_audiodevs)
665 return -ENXIO;
667 devc = (wavnc_info *) audio_devs[dev]->devc;
668 portc = (wavnc_port_info *) audio_devs[dev]->portc;
670 save_flags(flags);
671 cli();
672 if (portc->open_mode || (devc->open_mode & mode)) {
673 restore_flags(flags);
674 return -EBUSY;
677 devc->audio_mode = 0;
678 devc->open_mode |= mode;
679 portc->open_mode = mode;
680 waveartist_trigger(dev, 0);
682 if (mode & OPEN_READ)
683 devc->record_dev = dev;
684 if (mode & OPEN_WRITE)
685 devc->playback_dev = dev;
686 restore_flags(flags);
689 * Mute output until the playback really starts. This
690 * decreases clicking (hope so).
692 waveartist_mute(devc, 1);
694 return 0;
697 static void
698 waveartist_close(int dev)
700 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
701 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
702 unsigned long flags;
704 save_flags(flags);
705 cli();
707 waveartist_halt(dev);
709 devc->audio_mode = 0;
710 devc->open_mode &= ~portc->open_mode;
711 portc->open_mode = 0;
713 waveartist_mute(devc, 1);
715 restore_flags(flags);
718 static void
719 waveartist_output_block(int dev, unsigned long buf, int __count, int intrflag)
721 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
722 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
723 unsigned long flags;
724 unsigned int count = __count;
726 if (debug_flg & DEBUG_OUT)
727 printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
728 buf, count);
730 * 16 bit data
732 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE))
733 count >>= 1;
735 if (portc->channels > 1)
736 count >>= 1;
738 count -= 1;
740 if (devc->audio_mode & PCM_ENABLE_OUTPUT &&
741 audio_devs[dev]->flags & DMA_AUTOMODE &&
742 intrflag &&
743 count == devc->xfer_count) {
744 devc->audio_mode |= PCM_ENABLE_OUTPUT;
745 return; /*
746 * Auto DMA mode on. No need to react
750 save_flags(flags);
751 cli();
754 * set sample count
756 waveartist_cmd2(devc, 0x0024, count);
758 devc->xfer_count = count;
759 devc->audio_mode |= PCM_ENABLE_OUTPUT;
761 restore_flags(flags);
764 static void
765 waveartist_start_input(int dev, unsigned long buf, int __count, int intrflag)
767 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
768 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
769 unsigned long flags;
770 unsigned int count = __count;
772 if (debug_flg & DEBUG_IN)
773 printk("waveartist: start input, buf=0x%lx, count=0x%x...\n",
774 buf, count);
776 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
777 count >>= 1;
779 if (portc->channels > 1)
780 count >>= 1;
782 count -= 1;
784 if (devc->audio_mode & PCM_ENABLE_INPUT &&
785 audio_devs[dev]->flags & DMA_AUTOMODE &&
786 intrflag &&
787 count == devc->xfer_count) {
788 devc->audio_mode |= PCM_ENABLE_INPUT;
789 return; /*
790 * Auto DMA mode on. No need to react
794 save_flags(flags);
795 cli();
798 * set sample count
800 waveartist_cmd2(devc, 0x0014, count);
801 waveartist_mute(devc, 0);
803 devc->xfer_count = count;
804 devc->audio_mode |= PCM_ENABLE_INPUT;
806 restore_flags(flags);
809 static int
810 waveartist_ioctl(int dev, unsigned int cmd, caddr_t arg)
812 return -EINVAL;
815 static unsigned int
816 waveartist_get_speed(wavnc_port_info *portc)
818 unsigned int speed;
821 * program the speed, channels, bits
823 if (portc->speed == 8000)
824 speed = 0x2E71;
825 else if (portc->speed == 11025)
826 speed = 0x4000;
827 else if (portc->speed == 22050)
828 speed = 0x8000;
829 else if (portc->speed == 44100)
830 speed = 0x0;
831 else {
833 * non-standard - just calculate
835 speed = portc->speed << 16;
837 speed = (speed / 44100) & 65535;
840 return speed;
843 static unsigned int
844 waveartist_get_bits(wavnc_port_info *portc)
846 unsigned int bits;
848 if (portc->audio_format == AFMT_S16_LE)
849 bits = 1;
850 else if (portc->audio_format == AFMT_S8)
851 bits = 0;
852 else
853 bits = 2; //default AFMT_U8
855 return bits;
858 static int
859 waveartist_prepare_for_input(int dev, int bsize, int bcount)
861 unsigned long flags;
862 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
863 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
864 unsigned int speed, bits;
866 if (devc->audio_mode)
867 return 0;
869 speed = waveartist_get_speed(portc);
870 bits = waveartist_get_bits(portc);
872 save_flags(flags);
873 cli();
875 if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
876 printk("waveartist: error setting the record format to %d\n",
877 portc->audio_format);
879 if (waveartist_cmd2(devc, WACMD_INPUTCHANNELS, portc->channels))
880 printk("waveartist: error setting record to %d channels\n",
881 portc->channels);
884 * write cmd SetSampleSpeedTimeConstant
886 if (waveartist_cmd2(devc, WACMD_INPUTSPEED, speed))
887 printk("waveartist: error setting the record speed "
888 "to %dHz.\n", portc->speed);
890 if (waveartist_cmd2(devc, WACMD_INPUTDMA, 1))
891 printk("waveartist: error setting the record data path "
892 "to 0x%X\n", 1);
894 if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
895 printk("waveartist: error setting the record format to %d\n",
896 portc->audio_format);
898 devc->xfer_count = 0;
899 restore_flags(flags);
900 waveartist_halt_input(dev);
902 if (debug_flg & DEBUG_INTR) {
903 printk("WA CTLR reg: 0x%02X.\n",inb(devc->hw.io_base + CTLR));
904 printk("WA STAT reg: 0x%02X.\n",inb(devc->hw.io_base + STATR));
905 printk("WA IRQS reg: 0x%02X.\n",inb(devc->hw.io_base + IRQSTAT));
908 return 0;
911 static int
912 waveartist_prepare_for_output(int dev, int bsize, int bcount)
914 unsigned long flags;
915 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
916 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
917 unsigned int speed, bits;
920 * program the speed, channels, bits
922 speed = waveartist_get_speed(portc);
923 bits = waveartist_get_bits(portc);
925 save_flags(flags);
926 cli();
928 if (waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed) &&
929 waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed))
930 printk("waveartist: error setting the playback speed "
931 "to %dHz.\n", portc->speed);
933 if (waveartist_cmd2(devc, WACMD_OUTPUTCHANNELS, portc->channels))
934 printk("waveartist: error setting the playback to"
935 " %d channels\n", portc->channels);
937 if (waveartist_cmd2(devc, WACMD_OUTPUTDMA, 0))
938 printk("waveartist: error setting the playback data path "
939 "to 0x%X\n", 0);
941 if (waveartist_cmd2(devc, WACMD_OUTPUTFORMAT, bits))
942 printk("waveartist: error setting the playback format to %d\n",
943 portc->audio_format);
945 devc->xfer_count = 0;
946 restore_flags(flags);
947 waveartist_halt_output(dev);
949 if (debug_flg & DEBUG_INTR) {
950 printk("WA CTLR reg: 0x%02X.\n",inb(devc->hw.io_base + CTLR));
951 printk("WA STAT reg: 0x%02X.\n",inb(devc->hw.io_base + STATR));
952 printk("WA IRQS reg: 0x%02X.\n",inb(devc->hw.io_base + IRQSTAT));
955 return 0;
958 static void
959 waveartist_halt(int dev)
961 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
962 wavnc_info *devc;
965 if (portc->open_mode & OPEN_WRITE)
966 waveartist_halt_output(dev);
968 if (portc->open_mode & OPEN_READ)
969 waveartist_halt_input(dev);
971 devc = (wavnc_info *) audio_devs[dev]->devc;
972 devc->audio_mode = 0;
975 static void
976 waveartist_halt_input(int dev)
978 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
979 unsigned long flags;
981 save_flags(flags);
982 cli();
984 waveartist_mute(devc, 1);
986 //RMK disable_dma(audio_devs[dev]->dmap_in->dma);
989 * Stop capture
991 waveartist_sendcmd(&devc->hw, 0x17);
993 //RMK enable_dma(audio_devs[dev]->dmap_in->dma);
994 devc->audio_mode &= ~PCM_ENABLE_INPUT;
997 * Clear interrupt by toggling
998 * the IRQ_ACK bit in CTRL
1000 if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
1001 waveartist_iack(devc);
1003 // devc->audio_mode &= ~PCM_ENABLE_INPUT;
1005 restore_flags(flags);
1008 static void
1009 waveartist_halt_output(int dev)
1011 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
1012 unsigned long flags;
1014 save_flags(flags);
1015 cli();
1017 waveartist_mute(devc, 1);
1019 //RMK disable_dma(audio_devs[dev]->dmap_out->dma);
1021 waveartist_sendcmd(&devc->hw, 0x27);
1023 //RMK enable_dma(audio_devs[dev]->dmap_out->dma);
1025 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
1028 * Clear interrupt by toggling
1029 * the IRQ_ACK bit in CTRL
1031 if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
1032 waveartist_iack(devc);
1034 // devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
1036 restore_flags(flags);
1039 static void
1040 waveartist_trigger(int dev, int state)
1042 wavnc_info *devc = (wavnc_info *) audio_devs[dev]->devc;
1043 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
1044 unsigned long flags;
1046 if (debug_flg & DEBUG_TRIGGER) {
1047 printk("wavnc: audio trigger ");
1048 if (state & PCM_ENABLE_INPUT)
1049 printk("in ");
1050 if (state & PCM_ENABLE_OUTPUT)
1051 printk("out");
1052 printk("\n");
1055 save_flags(flags);
1056 cli();
1058 state &= devc->audio_mode;
1060 if (portc->open_mode & OPEN_READ &&
1061 state & PCM_ENABLE_INPUT)
1063 * enable ADC Data Transfer to PC
1065 waveartist_sendcmd(&devc->hw, 0x15);
1067 if (portc->open_mode & OPEN_WRITE &&
1068 state & PCM_ENABLE_OUTPUT)
1070 * enable DAC data transfer from PC
1072 waveartist_sendcmd(&devc->hw, 0x25);
1074 waveartist_mute(devc, 0);
1076 restore_flags(flags);
1079 static int
1080 waveartist_set_speed(int dev, int arg)
1082 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
1084 if (arg <= 0)
1085 return portc->speed;
1087 if (arg < 5000)
1088 arg = 5000;
1089 if (arg > 44100)
1090 arg = 44100;
1092 portc->speed = arg;
1093 return portc->speed;
1097 static short
1098 waveartist_set_channels(int dev, short arg)
1100 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
1102 if (arg != 1 && arg != 2)
1103 return portc->channels;
1105 portc->channels = arg;
1106 return arg;
1109 static unsigned int
1110 waveartist_set_bits(int dev, unsigned int arg)
1112 wavnc_port_info *portc = (wavnc_port_info *) audio_devs[dev]->portc;
1114 if (arg == 0)
1115 return portc->audio_format;
1117 if ((arg != AFMT_U8) && (arg != AFMT_S16_LE) && (arg != AFMT_S8))
1118 arg = AFMT_U8;
1120 portc->audio_format = arg;
1122 return arg;
1125 static struct audio_driver waveartist_audio_driver = {
1126 waveartist_open,
1127 waveartist_close,
1128 waveartist_output_block,
1129 waveartist_start_input,
1130 waveartist_ioctl,
1131 waveartist_prepare_for_input,
1132 waveartist_prepare_for_output,
1133 waveartist_halt,
1134 NULL,
1135 NULL,
1136 waveartist_halt_input,
1137 waveartist_halt_output,
1138 waveartist_trigger,
1139 waveartist_set_speed,
1140 waveartist_set_bits,
1141 waveartist_set_channels
1145 static void
1146 waveartist_intr(int irq, void *dev_id, struct pt_regs *regs)
1148 wavnc_info *devc = (wavnc_info *)dev_id;
1149 int irqstatus, status;
1151 irqstatus = inb(devc->hw.io_base + IRQSTAT);
1152 status = inb(devc->hw.io_base + STATR);
1154 if (debug_flg & DEBUG_INTR)
1155 printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
1156 status, irqstatus);
1158 if (status & IRQ_REQ) /* Clear interrupt */
1159 waveartist_iack(devc);
1160 else
1161 printk("waveartist: unexpected interrupt\n");
1163 #ifdef CONFIG_AUDIO
1164 if (irqstatus & 0x01) {
1165 int temp = 1;
1167 /* PCM buffer done
1169 if ((status & DMA0) && (devc->audio_mode & PCM_ENABLE_OUTPUT)) {
1170 DMAbuf_outputintr(devc->playback_dev, 1);
1171 temp = 0;
1173 if ((status & DMA1) && (devc->audio_mode & PCM_ENABLE_INPUT)) {
1174 DMAbuf_inputintr(devc->record_dev);
1175 temp = 0;
1177 if (temp) //default:
1178 printk("WaveArtist: Unknown interrupt\n");
1180 #endif
1181 if (irqstatus & 0x2)
1182 // We do not use SB mode natively...
1183 printk("WaveArtist: Unexpected SB interrupt...\n");
1186 /* -------------------------------------------------------------------------
1187 * Mixer stuff
1189 static void
1190 waveartist_mixer_update(wavnc_info *devc, int whichDev)
1192 unsigned int mask, reg_l, reg_r;
1193 unsigned int lev_left, lev_right;
1194 unsigned int vals[3];
1196 lev_left = devc->levels[whichDev] & 0xff;
1197 lev_right = devc->levels[whichDev] >> 8;
1199 #define SCALE(lev,max) ((lev) * (max) / 100)
1201 switch(whichDev) {
1202 case SOUND_MIXER_VOLUME:
1203 mask = 0x000e;
1204 reg_l = 0x200;
1205 reg_r = 0x600;
1206 lev_left = SCALE(lev_left, 7) << 1;
1207 lev_right = SCALE(lev_right, 7) << 1;
1208 break;
1210 case SOUND_MIXER_LINE:
1211 mask = 0x07c0;
1212 reg_l = 0x000;
1213 reg_r = 0x400;
1214 lev_left = SCALE(lev_left, 31) << 6;
1215 lev_right = SCALE(lev_right, 31) << 6;
1216 break;
1218 case SOUND_MIXER_MIC:
1219 mask = 0x0030;
1220 reg_l = 0x200;
1221 reg_r = 0x600;
1222 lev_left = SCALE(lev_left, 3) << 4;
1223 lev_right = SCALE(lev_right, 3) << 4;
1224 break;
1226 case SOUND_MIXER_RECLEV:
1227 mask = 0x000f;
1228 reg_l = 0x300;
1229 reg_r = 0x700;
1230 lev_left = SCALE(lev_left, 10);
1231 lev_right = SCALE(lev_right, 10);
1232 break;
1234 case SOUND_MIXER_LINE1:
1235 mask = 0x003e;
1236 reg_l = 0x000;
1237 reg_r = 0x400;
1238 lev_left = SCALE(lev_left, 31) << 1;
1239 lev_right = SCALE(lev_right, 31) << 1;
1240 break;
1242 case SOUND_MIXER_PCM:
1243 waveartist_cmd3(devc, 0x0031, SCALE(lev_left, 32767),
1244 SCALE(lev_right, 32767));
1245 return;
1247 case SOUND_MIXER_SYNTH:
1248 waveartist_cmd3(devc, 0x0131, SCALE(lev_left, 32767),
1249 SCALE(lev_right, 32767));
1250 return;
1252 default:
1253 return;
1256 /* read left setting */
1257 vals[0] = reg_l + 0x30;
1258 waveartist_cmd(devc, 1, vals, 1, vals + 1);
1260 /* read right setting */
1261 vals[0] = reg_r + 0x30;
1262 waveartist_cmd(devc, 1, vals, 1, vals + 2);
1264 vals[1] = (vals[1] & ~mask) | (lev_left & mask);
1265 vals[2] = (vals[2] & ~mask) | (lev_right & mask);
1267 /* write left,right back */
1268 vals[0] = 0x32;
1269 waveartist_cmd(devc, 3, vals, 0, NULL);
1272 static void
1273 waveartist_select_input(wavnc_info *devc, unsigned int input)
1275 unsigned int vals[3];
1276 #if 1
1277 /* New mixer programming - switch recording source
1278 * using R/L_ADC_Mux_Select. We are playing with
1279 * left/right mux bit fields in reg 9.
1281 * We can not switch Mux_Select while recording, so
1282 * for microphones, enable both left and right and
1283 * play with levels only!
1285 * Unfortunately, we need to select the src of mono
1286 * recording (left or right) before starting the
1287 * recording - so can not dynamically switch between
1288 * handset amd internal microphones...
1292 * Get reg 9
1294 vals[0] = 0x0830;
1295 waveartist_cmd(devc, 1, vals, 1, vals + 1);
1298 * Get reg 10, only so that we can write it back.
1300 vals[0] = 0x0930;
1301 waveartist_cmd(devc, 1, vals, 1, vals + 2);
1303 if (debug_flg & DEBUG_MIXER)
1304 printk("RECSRC: old left: 0x%04X, old right: 0x%04X.\n",
1305 vals[1] & 0x07, (vals[1] >> 3) & 0x07);
1307 vals[1] &= ~0x03F; //kill current left/right mux input select
1309 switch (input) {
1311 * Handset or internal MIC
1313 case SOUND_MASK_MIC:
1315 * handset not plugged in?
1317 if (devc->handset_state & VNC_INTERNAL_MIC) {
1319 * set mono recording from right mic
1321 waveartist_sendcmd(&devc->hw, 0x0134);
1322 #if 0
1324 * right=mic, left=none
1326 vals[1] |= 0x0028;
1328 * pretend int mic
1330 devc->rec_devices |= SOUND_MASK_SPEAKER;
1331 #endif
1332 } else {
1334 * set mono rec from left mic
1336 waveartist_sendcmd(&devc->hw, 0x0034);
1337 #if 0
1339 * right=none, left=mic
1341 vals[1] |= 0x0005;
1343 * show no int mic
1345 devc->rec_devices &= ~SOUND_MASK_SPEAKER;
1346 #endif
1349 * right=mic, left=mic
1351 vals[1] |= 0x002D;
1352 break;
1354 case SOUND_MASK_LINE1:
1356 * set mono rec from left aux1
1358 waveartist_sendcmd(&devc->hw, 0x0034);
1360 * right=none, left=Aux1;
1362 vals[1] |= 0x0004;
1363 break;
1365 case SOUND_MASK_LINE:
1367 * set mono rec from left (default)
1369 waveartist_sendcmd(&devc->hw, 0x0034);
1371 * right=Line, left=Line;
1373 vals[1] |= 0x0012;
1374 break;
1377 if (debug_flg & DEBUG_MIXER)
1378 printk("RECSRC %d: left=0x%04X, right=0x%04X.\n", input,
1379 vals[1] & 0x07, (vals[1] >> 3) & 0x07);
1381 #else
1382 /* This part is good, if input connected to
1383 * a mixer, so can be used for record-only modes...
1387 * get reg 4
1389 vals[0] = 0x0330;
1390 waveartist_cmd(devc, 1, vals, 1, vals + 1);
1393 * get reg 8
1395 vals[0] = 0x0730;
1396 waveartist_cmd(devc, 1, vals, 1, vals + 2);
1398 if (debug_flg & DEBUG_MIXER)
1399 printk("RECSRC: old left: 0x%04X, old right: 0x%04X.\n",
1400 vals[1], vals[2]);
1403 * kill current left/right mux input select
1405 vals[1] &= ~0x07F8;
1406 vals[2] &= ~0x07F8;
1408 switch (input) {
1410 * handset or internal mic
1412 case SOUND_MASK_MIC:
1414 * handset not plugged in?
1416 if (devc->handset_state & VNC_INTERNAL_MIC) {
1418 * set mono recording from right mic
1420 waveartist_sendcmd(&devc->hw, 0x0134);
1422 * left = none, right = mic, RX filter gain
1424 vals[1] |= 0x0C00;
1425 vals[2] |= 0x0C88;
1427 * pretend int mic
1429 devc->rec_devices |= SOUND_MASK_SPEAKER;
1430 } else {
1432 * set mono rec from left mic
1434 waveartist_sendcmd(&devc->hw, 0x0034);
1436 * left = mic, RX filter gain, right = none;
1438 vals[1] |= 0x0C88;
1439 vals[2] |= 0x0C00;
1441 * show no int mic
1443 devc->rec_devices &= ~SOUND_MASK_SPEAKER;
1445 break;
1447 case SOUND_MASK_LINE1:
1449 * set mono rec from left aux1
1451 waveartist_sendcmd(&devc->hw, 0x0034);
1453 * left = Aux1, right = none
1455 vals[1] |= 0x0C40;
1456 vals[2] |= 0x0C00;
1457 break;
1459 case SOUND_MASK_LINE:
1461 * left = Line, right = Line
1463 vals[1] |= 0x0C10;
1464 vals[2] |= 0x0C10;
1465 break;
1468 if (debug_flg & DEBUG_MIXER)
1469 printk("RECSRC %d: left(4) 0x%04X, right(8) 0x%04X.\n",
1470 level, vals[1], vals[2]);
1471 #endif
1473 * and finally - write the reg pair back....
1475 vals[0] = 0x32;
1477 waveartist_cmd(devc, 3, vals, 0, NULL);
1480 static int
1481 waveartist_mixer_set(wavnc_info *devc, int whichDev, unsigned int level)
1483 unsigned int lev_left = level & 0x007f;
1484 unsigned int lev_right = (level & 0x7f00) >> 8;
1486 int left, right, devmask, changed, i;
1488 left = level & 0x7f;
1489 right = (level & 0x7f00) >> 8;
1491 if (debug_flg & DEBUG_MIXER)
1492 printk("wa_mixer_set(dev=%d, level=%X)\n",
1493 whichDev, level);
1495 switch (whichDev) {
1496 /* Master volume (0-7)
1497 * We have 3 bits on the Left/Right Mixer Gain,
1498 * bits 3,2,1 on 3 and 7
1500 case SOUND_MIXER_VOLUME:
1501 devc->levels[whichDev] = lev_left | lev_right << 8;
1502 waveartist_mixer_update(devc, whichDev);
1503 break;
1506 /* External line (0-31)
1507 * use LOUT/ROUT bits 10...6, reg 1 and 5
1509 case SOUND_MIXER_LINE:
1510 devc->levels[whichDev] = lev_left | lev_right << 8;
1511 waveartist_mixer_update(devc, whichDev);
1512 break;
1514 /* Mono microphone (0-3) mute,
1515 * 0db,10db,20db
1517 case SOUND_MIXER_MIC:
1518 #if 1
1519 devc->levels[whichDev] = lev_left | lev_right << 8;
1520 #else
1521 /* we do not need to mute volume of
1522 * an unused mic - it is simply unused...
1524 if (devc->handset_state & VNC_INTERNAL_MIC)
1525 devc->levels[whichDev] = lev_right << 8;
1526 else
1527 levels[whichDev] = lev_left;
1528 #endif
1529 waveartist_mixer_update(devc, whichDev);
1530 break;
1532 /* Recording level (0-7)
1534 case SOUND_MIXER_RECLEV:
1535 devc->levels[whichDev] = lev_left | lev_right << 8;
1536 waveartist_mixer_update(devc, whichDev);
1537 break;
1539 /* Mono External Aux1 (0-31)
1540 * use LINE1 bits 5...1, reg 1 and 5
1542 case SOUND_MIXER_LINE1:
1543 devc->levels[whichDev] = lev_left | lev_right << 8;
1544 waveartist_mixer_update(devc, whichDev);
1545 break;
1547 /* WaveArtist PCM (0-32767)
1549 case SOUND_MIXER_PCM:
1550 devc->levels[whichDev] = lev_left | lev_right << 8;
1551 waveartist_mixer_update(devc, whichDev);
1552 break;
1554 /* Internal synthesizer (0-31)
1556 case SOUND_MIXER_SYNTH:
1557 devc->levels[whichDev] = lev_left | lev_right << 8;
1558 waveartist_mixer_update(devc, whichDev);
1559 break;
1562 /* Select recording input source
1564 case SOUND_MIXER_RECSRC:
1565 devmask = level & POSSIBLE_RECORDING_DEVICES;
1567 changed = devmask ^ devc->recmask;
1568 devc->recmask = devmask;
1570 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1571 if (changed & (1 << i))
1572 waveartist_mixer_update(devc, i);
1574 waveartist_select_input(devc, level);
1576 * do not save in "levels", return current setting
1578 return devc->recmask;
1580 default:
1581 return -EINVAL;
1584 return devc->levels[whichDev];
1587 static void
1588 waveartist_mixer_reset(wavnc_info *devc)
1590 int i;
1592 if (debug_flg & DEBUG_MIXER)
1593 printk("%s: mixer_reset\n", devc->hw.name);
1596 * reset mixer cmd
1598 waveartist_sendcmd(&devc->hw, 0x33);
1601 * set input for ADC to come from
1602 * a mux (left and right) == reg 9,
1603 * initially none
1605 waveartist_cmd3(devc, 0x0032, 0x9800, 0xa836);
1608 * set mixer input select to none, RX filter gains 0 db
1610 waveartist_cmd3(devc, 0x0032, 0x4c00, 0x8c00);
1613 * set bit 0 reg 2 to 1 - unmute MonoOut
1615 waveartist_cmd3(devc, 0x0032, 0x2801, 0x6800);
1617 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1618 waveartist_mixer_update(devc, i);
1620 /* set default input device = internal mic
1621 * current recording device = none
1622 * no handset
1624 devc->recmask = 0;
1625 devc->handset_state = VNC_INTERNAL_MIC;
1626 // waveartist_mixer_set(devc, SOUND_MIXER_RECSRC, SOUND_MASK_MIC);
1629 * start from enabling the hw setting
1631 devc->handset_mute_sw = 0;
1632 devc->supported_devices = SUPPORTED_MIXER_DEVICES;
1633 devc->rec_devices = POSSIBLE_RECORDING_DEVICES;
1636 static int
1637 waveartist_mixer_ioctl(int dev, unsigned int cmd, caddr_t arg)
1639 wavnc_info *devc = (wavnc_info *)audio_devs[dev]->devc;
1641 if (cmd == SOUND_MIXER_PRIVATE1 ||
1642 cmd == SOUND_MIXER_PRIVATE2 ||
1643 cmd == SOUND_MIXER_PRIVATE3)
1644 return vnc_private_ioctl(dev, cmd, arg);
1646 if (((cmd >> 8) & 0xff) == 'M') {
1647 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1648 int val;
1650 if (get_user(val, (int *)arg))
1651 return -EFAULT;
1654 * special case for master volume: if we
1655 * received this call - switch from hw
1656 * volume control to a software volume
1657 * control, till the hw volume is modified
1658 * to signal that user wants to be back in
1659 * hardware...
1661 if ((cmd & 0xff) == SOUND_MIXER_VOLUME)
1662 devc->use_slider = 0;
1664 return waveartist_mixer_set(devc, cmd & 0xff, val);
1665 } else {
1666 int ret;
1669 * Return parameters
1671 switch (cmd & 0xff) {
1672 case SOUND_MIXER_RECSRC:
1673 ret = devc->recmask;
1675 if (devc->handset_state & VNC_INTERNAL_MIC)
1676 ret |= SOUND_MASK_SPEAKER;
1677 break;
1679 case SOUND_MIXER_DEVMASK:
1680 ret = devc->supported_devices;
1681 break;
1683 case SOUND_MIXER_STEREODEVS:
1684 ret = devc->supported_devices &
1685 ~(SOUND_MASK_SPEAKER|SOUND_MASK_IMIX);
1686 break;
1688 case SOUND_MIXER_RECMASK:
1689 ret = devc->rec_devices;
1690 break;
1692 case SOUND_MIXER_CAPS:
1693 ret = SOUND_CAP_EXCL_INPUT;
1694 break;
1696 default:
1697 if ((cmd & 0xff) < SOUND_MIXER_NRDEVICES)
1698 ret = devc->levels[cmd & 0xff];
1699 else
1700 return -EINVAL;
1703 return put_user(ret, (int *)arg) ? -EINVAL : 0;
1707 return -ENOIOCTLCMD;
1710 static struct mixer_operations waveartist_mixer_operations =
1712 "WaveArtist",
1713 "WaveArtist NetWinder",
1714 waveartist_mixer_ioctl
1717 static int
1718 waveartist_init(wavnc_info *devc)
1720 wavnc_port_info *portc;
1721 char rev[3], dev_name[64];
1722 int my_dev;
1724 waveartist_reset(devc);
1726 sprintf(dev_name, "%s (%s", devc->hw.name, devc->chip_name);
1728 if (waveartist_getrev(&devc->hw, rev)) {
1729 strcat(dev_name, " rev. ");
1730 strcat(dev_name, rev);
1732 strcat(dev_name, ")");
1734 conf_printf2(dev_name, devc->hw.io_base, devc->hw.irq,
1735 devc->hw.dma, devc->hw.dma2);
1737 portc = (wavnc_port_info *)kmalloc(sizeof(wavnc_port_info), GFP_KERNEL);
1738 if (portc == NULL)
1739 goto nomem;
1741 memset(portc, 0, sizeof(wavnc_port_info));
1743 my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION, dev_name,
1744 &waveartist_audio_driver, sizeof(struct audio_driver),
1745 devc->audio_flags, AFMT_U8 | AFMT_S16_LE | AFMT_S8,
1746 devc, devc->hw.dma, devc->hw.dma2);
1748 if (my_dev < 0)
1749 goto free;
1751 audio_devs[my_dev]->portc = portc;
1753 waveartist_mixer_reset(devc);
1756 * clear any pending interrupt
1758 waveartist_iack(devc);
1760 if (request_irq(devc->hw.irq, waveartist_intr, 0, devc->hw.name, devc) < 0) {
1761 printk("%s: IRQ %d in use\n",
1762 devc->hw.name, devc->hw.irq);
1763 goto uninstall;
1766 if (sound_alloc_dma(devc->hw.dma, devc->hw.name)) {
1767 printk("%s: Can't allocate DMA%d\n",
1768 devc->hw.name, devc->hw.dma);
1769 goto uninstall_irq;
1772 if (devc->hw.dma != devc->hw.dma2 && devc->hw.dma2 != NO_DMA)
1773 if (sound_alloc_dma(devc->hw.dma2, devc->hw.name)) {
1774 printk("%s: can't allocate DMA%d\n",
1775 devc->hw.name, devc->hw.dma2);
1776 goto uninstall_dma;
1779 waveartist_set_ctlr(&devc->hw, 0, DMA1_IE | DMA0_IE);
1781 audio_devs[my_dev]->mixer_dev =
1782 sound_install_mixer(MIXER_DRIVER_VERSION,
1783 dev_name,
1784 &waveartist_mixer_operations,
1785 sizeof(struct mixer_operations),
1786 devc);
1788 return my_dev;
1790 uninstall_dma:
1791 sound_free_dma(devc->hw.dma);
1793 uninstall_irq:
1794 free_irq(devc->hw.irq, devc);
1796 uninstall:
1797 sound_unload_audiodev(my_dev);
1799 free:
1800 kfree(portc);
1802 nomem:
1803 return -1;
1807 probe_waveartist(struct address_info *hw_config)
1809 wavnc_info *devc = &adev_info[nr_waveartist_devs];
1811 if (nr_waveartist_devs >= MAX_AUDIO_DEV) {
1812 printk("waveartist: too many audio devices\n");
1813 return 0;
1816 if (check_region(hw_config->io_base, 15)) {
1817 printk("WaveArtist: I/O port conflict\n");
1818 return 0;
1821 if (hw_config->irq > _ISA_IRQ(15) || hw_config->irq < _ISA_IRQ(0)) {
1822 printk("WaveArtist: Bad IRQ %d\n", hw_config->irq);
1823 return 0;
1826 if (hw_config->dma != _ISA_DMA(3)) {
1827 printk("WaveArtist: Bad DMA %d\n", hw_config->dma);
1828 return 0;
1831 hw_config->name = "WaveArtist";
1832 devc->hw = *hw_config;
1833 devc->open_mode = 0;
1834 devc->chip_name = "RWA-010";
1836 return 1;
1839 void
1840 attach_waveartist(struct address_info *hw)
1842 wavnc_info *devc = &adev_info[nr_waveartist_devs];
1845 * NOTE! If irq < 0, there is another driver which has allocated the
1846 * IRQ so that this driver doesn't need to allocate/deallocate it.
1847 * The actually used IRQ is ABS(irq).
1849 devc->hw = *hw;
1850 devc->hw.irq = (hw->irq > 0) ? hw->irq : 0;
1851 devc->open_mode = 0;
1852 devc->playback_dev = 0;
1853 devc->record_dev = 0;
1854 devc->audio_flags = DMA_AUTOMODE;
1855 devc->levels = levels;
1857 if (hw->dma != hw->dma2 && hw->dma2 != NO_DMA)
1858 devc->audio_flags |= DMA_DUPLEX;
1860 request_region(hw->io_base, 15, devc->hw.name);
1862 devc->dev_no = waveartist_init(devc);
1864 if (devc->dev_no < 0)
1865 release_region(hw->io_base, 15);
1866 else {
1867 init_timer(&vnc_timer);
1868 vnc_timer.function = vnc_slider_tick;
1869 vnc_timer.expires = jiffies;
1870 vnc_timer.data = nr_waveartist_devs;
1871 add_timer(&vnc_timer);
1873 nr_waveartist_devs += 1;
1875 vnc_mute(devc, 0);
1879 void
1880 unload_waveartist(struct address_info *hw)
1882 wavnc_info *devc = NULL;
1883 int i;
1885 for (i = 0; i < nr_waveartist_devs; i++)
1886 if (hw->io_base == adev_info[i].hw.io_base) {
1887 devc = adev_info + i;
1888 break;
1891 if (devc != NULL) {
1892 int mixer;
1894 release_region(devc->hw.io_base, 15);
1896 waveartist_set_ctlr(&devc->hw, DMA1_IE|DMA0_IE, 0);
1898 if (devc->hw.irq >= 0)
1899 free_irq(devc->hw.irq, devc);
1901 sound_free_dma(devc->hw.dma);
1903 if (devc->hw.dma != devc->hw.dma2 &&
1904 devc->hw.dma2 != NO_DMA)
1905 sound_free_dma(devc->hw.dma2);
1907 del_timer(&vnc_timer);
1909 mixer = audio_devs[devc->dev_no]->mixer_dev;
1911 if (mixer >= 0)
1912 sound_unload_mixerdev(mixer);
1914 if (devc->dev_no >= 0)
1915 sound_unload_audiodev(devc->dev_no);
1917 nr_waveartist_devs -= 1;
1919 for (; i < nr_waveartist_devs; i++)
1920 adev_info[i] = adev_info[i + 1];
1921 } else
1922 printk("waveartist: can't find device to unload\n");
1925 #ifdef MODULE
1927 MODULE_PARM(io, "i"); /* IO base */
1928 MODULE_PARM(irq, "i"); /* IRQ */
1929 MODULE_PARM(dma, "i"); /* DMA */
1930 MODULE_PARM(dma2, "i"); /* DMA2 */
1932 int io = CONFIG_WAVEARTIST_BASE;
1933 int irq = CONFIG_WAVEARTIST_IRQ;
1934 int dma = CONFIG_WAVEARTIST_DMA;
1935 int dma2 = CONFIG_WAVEARTIST_DMA2;
1937 static int attached;
1939 struct address_info hw_config;
1941 int init_module(void)
1943 hw_config.io_base = io;
1944 hw_config.irq = irq;
1945 hw_config.dma = dma;
1946 hw_config.dma2 = dma2;
1948 if (!probe_waveartist(&hw_config))
1949 return -ENODEV;
1951 attach_waveartist(&hw_config);
1952 attached = 1;
1954 SOUND_LOCK;
1955 return 0;
1958 void cleanup_module(void)
1960 if (attached) {
1961 SOUND_LOCK_END;
1963 unload_waveartist(&hw_config);
1966 #endif