~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/oss/waveartist.c

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * linux/sound/oss/waveartist.c
  3  *
  4  * The low level driver for the RWA010 Rockwell Wave Artist
  5  * codec chip used in the Rebel.com NetWinder.
  6  *
  7  * Cleaned up and integrated into 2.1 by Russell King (rmk@arm.linux.org.uk)
  8  * and Pat Beirne (patb@corel.ca)
  9  *
 10  *
 11  * Copyright (C) by Rebel.com 1998-1999
 12  *
 13  * RWA010 specs received under NDA from Rockwell
 14  *
 15  * Copyright (C) by Hannu Savolainen 1993-1997
 16  *
 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.
 20  *
 21  * Changes:
 22  * 11-10-2000   Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
 23  *              Added __init to waveartist_init()
 24  */
 25 
 26 /* Debugging */
 27 #define DEBUG_CMD       1
 28 #define DEBUG_OUT       2
 29 #define DEBUG_IN        4
 30 #define DEBUG_INTR      8
 31 #define DEBUG_MIXER     16
 32 #define DEBUG_TRIGGER   32
 33 
 34 #define debug_flg (0)
 35 
 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>
 44 
 45 
 46 #include "sound_config.h"
 47 #include "waveartist.h"
 48 
 49 #ifdef CONFIG_ARM
 50 #include <mach/hardware.h>
 51 #include <asm/mach-types.h>
 52 #endif
 53 
 54 #ifndef NO_DMA
 55 #define NO_DMA  255
 56 #endif
 57 
 58 #define SUPPORTED_MIXER_DEVICES         (SOUND_MASK_SYNTH      |\
 59                                          SOUND_MASK_PCM        |\
 60                                          SOUND_MASK_LINE       |\
 61                                          SOUND_MASK_MIC        |\
 62                                          SOUND_MASK_LINE1      |\
 63                                          SOUND_MASK_RECLEV     |\
 64                                          SOUND_MASK_VOLUME     |\
 65                                          SOUND_MASK_IMIX)
 66 
 67 static unsigned short levels[SOUND_MIXER_NRDEVICES] = {
 68         0x5555,         /* Master Volume         */
 69         0x0000,         /* Bass                  */
 70         0x0000,         /* Treble                */
 71         0x2323,         /* Synth (FM)            */
 72         0x4b4b,         /* PCM                   */
 73         0x6464,         /* PC Speaker            */
 74         0x0000,         /* Ext Line              */
 75         0x0000,         /* Mic                   */
 76         0x0000,         /* CD                    */
 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             */
 90         0x0000,         /* Video                 */
 91         0x0000,         /* Radio                 */
 92         0x0000          /* Monitor               */
 93 };
 94 
 95 struct wavnc_info {
 96         struct address_info  hw;        /* hardware */
 97         char            *chip_name;
 98 
 99         int             xfer_count;
100         int             audio_mode;
101         int             open_mode;
102         int             audio_flags;
103         int             record_dev;
104         int             playback_dev;
105         int             dev_no;
106 
107         /* Mixer parameters */
108         const struct waveartist_mixer_info *mix;
109 
110         unsigned short  *levels;           /* cache of volume settings   */
111         int             recmask;           /* currently enabled recording device! */
112 
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 */
121 #endif
122 };
123 
124 /*
125  * This is the implementation specific mixer information.
126  */
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    */
131 
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);
137 };
138 
139 struct wavnc_port_info {
140         int             open_mode;
141         int             speed;
142         int             channels;
143         int             audio_format;
144 };
145 
146 static int              nr_waveartist_devs;
147 static struct wavnc_info        adev_info[MAX_AUDIO_DEV];
148 static DEFINE_SPINLOCK(waveartist_lock);
149 
150 #ifndef CONFIG_ARCH_NETWINDER
151 #define machine_is_netwinder() 0
152 #else
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);
158 #endif
159 
160 static inline void
161 waveartist_set_ctlr(struct address_info *hw, unsigned char clear, unsigned char set)
162 {
163         unsigned int ctlr_port = hw->io_base + CTLR;
164 
165         clear = ~clear & inb(ctlr_port);
166 
167         outb(clear | set, ctlr_port);
168 }
169 
170 /* Toggle IRQ acknowledge line
171  */
172 static inline void
173 waveartist_iack(struct wavnc_info *devc)
174 {
175         unsigned int ctlr_port = devc->hw.io_base + CTLR;
176         int old_ctlr;
177 
178         old_ctlr = inb(ctlr_port) & ~IRQ_ACK;
179 
180         outb(old_ctlr | IRQ_ACK, ctlr_port);
181         outb(old_ctlr, ctlr_port);
182 }
183 
184 static inline int
185 waveartist_sleep(int timeout_ms)
186 {
187         unsigned int timeout = msecs_to_jiffies(timeout_ms*100);
188         return schedule_timeout_interruptible(timeout);
189 }
190 
191 static int
192 waveartist_reset(struct wavnc_info *devc)
193 {
194         struct address_info *hw = &devc->hw;
195         unsigned int timeout, res = -1;
196 
197         waveartist_set_ctlr(hw, -1, RESET);
198         waveartist_sleep(2);
199         waveartist_set_ctlr(hw, RESET, 0);
200 
201         timeout = 500;
202         do {
203                 mdelay(2);
204 
205                 if (inb(hw->io_base + STATR) & CMD_RF) {
206                         res = inw(hw->io_base + CMDR);
207                         if (res == 0x55aa)
208                                 break;
209                 }
210         } while (--timeout);
211 
212         if (timeout == 0) {
213                 printk(KERN_WARNING "WaveArtist: reset timeout ");
214                 if (res != (unsigned int)-1)
215                         printk("(res=%04X)", res);
216                 printk("\n");
217                 return 1;
218         }
219         return 0;
220 }
221 
222 /* Helper function to send and receive words
223  * from WaveArtist.  It handles all the handshaking
224  * and can send or receive multiple words.
225  */
226 static int
227 waveartist_cmd(struct wavnc_info *devc,
228                 int nr_cmd, unsigned int *cmd,
229                 int nr_resp, unsigned int *resp)
230 {
231         unsigned int io_base = devc->hw.io_base;
232         unsigned int timed_out = 0;
233         unsigned int i;
234 
235         if (debug_flg & DEBUG_CMD) {
236                 printk("waveartist_cmd: cmd=");
237 
238                 for (i = 0; i < nr_cmd; i++)
239                         printk("%04X ", cmd[i]);
240 
241                 printk("\n");
242         }
243 
244         if (inb(io_base + STATR) & CMD_RF) {
245                 int old_data;
246 
247                 /* flush the port
248                  */
249 
250                 old_data = inw(io_base + CMDR);
251 
252                 if (debug_flg & DEBUG_CMD)
253                         printk("flushed %04X...", old_data);
254 
255                 udelay(10);
256         }
257 
258         for (i = 0; !timed_out && i < nr_cmd; i++) {
259                 int count;
260 
261                 for (count = 5000; count; count--)
262                         if (inb(io_base + STATR) & CMD_WE)
263                                 break;
264 
265                 if (!count)
266                         timed_out = 1;
267                 else
268                         outw(cmd[i], io_base + CMDR);
269         }
270 
271         for (i = 0; !timed_out && i < nr_resp; i++) {
272                 int count;
273 
274                 for (count = 5000; count; count--)
275                         if (inb(io_base + STATR) & CMD_RF)
276                                 break;
277 
278                 if (!count)
279                         timed_out = 1;
280                 else
281                         resp[i] = inw(io_base + CMDR);
282         }
283 
284         if (debug_flg & DEBUG_CMD) {
285                 if (!timed_out) {
286                         printk("waveartist_cmd: resp=");
287 
288                         for (i = 0; i < nr_resp; i++)
289                                 printk("%04X ", resp[i]);
290 
291                         printk("\n");
292                 } else
293                         printk("waveartist_cmd: timed out\n");
294         }
295 
296         return timed_out ? 1 : 0;
297 }
298 
299 /*
300  * Send one command word
301  */
302 static inline int
303 waveartist_cmd1(struct wavnc_info *devc, unsigned int cmd)
304 {
305         return waveartist_cmd(devc, 1, &cmd, 0, NULL);
306 }
307 
308 /*
309  * Send one command, receive one word
310  */
311 static inline unsigned int
312 waveartist_cmd1_r(struct wavnc_info *devc, unsigned int cmd)
313 {
314         unsigned int ret;
315 
316         waveartist_cmd(devc, 1, &cmd, 1, &ret);
317 
318         return ret;
319 }
320 
321 /*
322  * Send a double command, receive one
323  * word (and throw it away)
324  */
325 static inline int
326 waveartist_cmd2(struct wavnc_info *devc, unsigned int cmd, unsigned int arg)
327 {
328         unsigned int vals[2];
329 
330         vals[0] = cmd;
331         vals[1] = arg;
332 
333         return waveartist_cmd(devc, 2, vals, 1, vals);
334 }
335 
336 /*
337  * Send a triple command
338  */
339 static inline int
340 waveartist_cmd3(struct wavnc_info *devc, unsigned int cmd,
341                 unsigned int arg1, unsigned int arg2)
342 {
343         unsigned int vals[3];
344 
345         vals[0] = cmd;
346         vals[1] = arg1;
347         vals[2] = arg2;
348 
349         return waveartist_cmd(devc, 3, vals, 0, NULL);
350 }
351 
352 static int
353 waveartist_getrev(struct wavnc_info *devc, char *rev)
354 {
355         unsigned int temp[2];
356         unsigned int cmd = WACMD_GETREV;
357 
358         waveartist_cmd(devc, 1, &cmd, 2, temp);
359 
360         rev[0] = temp[0] >> 8;
361         rev[1] = temp[0] & 255;
362         rev[2] = '\0';
363 
364         return temp[0];
365 }
366 
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);
371 
372 static int
373 waveartist_open(int dev, int mode)
374 {
375         struct wavnc_info       *devc;
376         struct wavnc_port_info  *portc;
377         unsigned long   flags;
378 
379         if (dev < 0 || dev >= num_audiodevs)
380                 return -ENXIO;
381 
382         devc  = (struct wavnc_info *) audio_devs[dev]->devc;
383         portc = (struct wavnc_port_info *) audio_devs[dev]->portc;
384 
385         spin_lock_irqsave(&waveartist_lock, flags);
386         if (portc->open_mode || (devc->open_mode & mode)) {
387                 spin_unlock_irqrestore(&waveartist_lock, flags);
388                 return -EBUSY;
389         }
390 
391         devc->audio_mode  = 0;
392         devc->open_mode  |= mode;
393         portc->open_mode  = mode;
394         waveartist_trigger(dev, 0);
395 
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);
401 
402         return 0;
403 }
404 
405 static void
406 waveartist_close(int dev)
407 {
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;
412         unsigned long   flags;
413 
414         spin_lock_irqsave(&waveartist_lock, flags);
415 
416         waveartist_halt(dev);
417 
418         devc->audio_mode = 0;
419         devc->open_mode &= ~portc->open_mode;
420         portc->open_mode = 0;
421 
422         spin_unlock_irqrestore(&waveartist_lock, flags);
423 }
424 
425 static void
426 waveartist_output_block(int dev, unsigned long buf, int __count, int intrflag)
427 {
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;
432         unsigned long   flags;
433         unsigned int    count = __count; 
434 
435         if (debug_flg & DEBUG_OUT)
436                 printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
437                         buf, count);
438         /*
439          * 16 bit data
440          */
441         if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE))
442                 count >>= 1;
443 
444         if (portc->channels > 1)
445                 count >>= 1;
446 
447         count -= 1;
448 
449         if (devc->audio_mode & PCM_ENABLE_OUTPUT &&
450             audio_devs[dev]->flags & DMA_AUTOMODE &&
451             intrflag &&
452             count == devc->xfer_count) {
453                 devc->audio_mode |= PCM_ENABLE_OUTPUT;
454                 return; /*
455                          * Auto DMA mode on. No need to react
456                          */
457         }
458 
459         spin_lock_irqsave(&waveartist_lock, flags);
460 
461         /*
462          * set sample count
463          */
464         waveartist_cmd2(devc, WACMD_OUTPUTSIZE, count);
465 
466         devc->xfer_count = count;
467         devc->audio_mode |= PCM_ENABLE_OUTPUT;
468 
469         spin_unlock_irqrestore(&waveartist_lock, flags);
470 }
471 
472 static void
473 waveartist_start_input(int dev, unsigned long buf, int __count, int intrflag)
474 {
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;
479         unsigned long   flags;
480         unsigned int    count = __count;
481 
482         if (debug_flg & DEBUG_IN)
483                 printk("waveartist: start input, buf=0x%lx, count=0x%x...\n",
484                         buf, count);
485 
486         if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE))  /* 16 bit data */
487                 count >>= 1;
488 
489         if (portc->channels > 1)
490                 count >>= 1;
491 
492         count -= 1;
493 
494         if (devc->audio_mode & PCM_ENABLE_INPUT &&
495             audio_devs[dev]->flags & DMA_AUTOMODE &&
496             intrflag &&
497             count == devc->xfer_count) {
498                 devc->audio_mode |= PCM_ENABLE_INPUT;
499                 return; /*
500                          * Auto DMA mode on. No need to react
501                          */
502         }
503 
504         spin_lock_irqsave(&waveartist_lock, flags);
505 
506         /*
507          * set sample count
508          */
509         waveartist_cmd2(devc, WACMD_INPUTSIZE, count);
510 
511         devc->xfer_count = count;
512         devc->audio_mode |= PCM_ENABLE_INPUT;
513 
514         spin_unlock_irqrestore(&waveartist_lock, flags);
515 }
516 
517 static int
518 waveartist_ioctl(int dev, unsigned int cmd, void __user * arg)
519 {
520         return -EINVAL;
521 }
522 
523 static unsigned int
524 waveartist_get_speed(struct wavnc_port_info *portc)
525 {
526         unsigned int speed;
527 
528         /*
529          * program the speed, channels, bits
530          */
531         if (portc->speed == 8000)
532                 speed = 0x2E71;
533         else if (portc->speed == 11025)
534                 speed = 0x4000;
535         else if (portc->speed == 22050)
536                 speed = 0x8000;
537         else if (portc->speed == 44100)
538                 speed = 0x0;
539         else {
540                 /*
541                  * non-standard - just calculate
542                  */
543                 speed = portc->speed << 16;
544 
545                 speed = (speed / 44100) & 65535;
546         }
547 
548         return speed;
549 }
550 
551 static unsigned int
552 waveartist_get_bits(struct wavnc_port_info *portc)
553 {
554         unsigned int bits;
555 
556         if (portc->audio_format == AFMT_S16_LE)
557                 bits = 1;
558         else if (portc->audio_format == AFMT_S8)
559                 bits = 0;
560         else
561                 bits = 2;       //default AFMT_U8
562 
563         return bits;
564 }
565 
566 static int
567 waveartist_prepare_for_input(int dev, int bsize, int bcount)
568 {
569         unsigned long   flags;
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;
575 
576         if (devc->audio_mode)
577                 return 0;
578 
579         speed = waveartist_get_speed(portc);
580         bits  = waveartist_get_bits(portc);
581 
582         spin_lock_irqsave(&waveartist_lock, flags);
583 
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);
587 
588         if (waveartist_cmd2(devc, WACMD_INPUTCHANNELS, portc->channels))
589                 printk(KERN_WARNING "waveartist: error setting record "
590                        "to %d channels\n", portc->channels);
591 
592         /*
593          * write cmd SetSampleSpeedTimeConstant
594          */
595         if (waveartist_cmd2(devc, WACMD_INPUTSPEED, speed))
596                 printk(KERN_WARNING "waveartist: error setting the record "
597                        "speed to %dHz.\n", portc->speed);
598 
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);
602 
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);
606 
607         devc->xfer_count = 0;
608         spin_unlock_irqrestore(&waveartist_lock, flags);
609         waveartist_halt_input(dev);
610 
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));
618         }
619 
620         return 0;
621 }
622 
623 static int
624 waveartist_prepare_for_output(int dev, int bsize, int bcount)
625 {
626         unsigned long   flags;
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;
632 
633         /*
634          * program the speed, channels, bits
635          */
636         speed = waveartist_get_speed(portc);
637         bits  = waveartist_get_bits(portc);
638 
639         spin_lock_irqsave(&waveartist_lock, flags);
640 
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);
645 
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);
649 
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);
653 
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);
657 
658         devc->xfer_count = 0;
659         spin_unlock_irqrestore(&waveartist_lock, flags);
660         waveartist_halt_output(dev);
661 
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));
666         }
667 
668         return 0;
669 }
670 
671 static void
672 waveartist_halt(int dev)
673 {
674         struct wavnc_port_info  *portc = (struct wavnc_port_info *)
675                                          audio_devs[dev]->portc;
676         struct wavnc_info       *devc;
677 
678         if (portc->open_mode & OPEN_WRITE)
679                 waveartist_halt_output(dev);
680 
681         if (portc->open_mode & OPEN_READ)
682                 waveartist_halt_input(dev);
683 
684         devc = (struct wavnc_info *) audio_devs[dev]->devc;
685         devc->audio_mode = 0;
686 }
687 
688 static void
689 waveartist_halt_input(int dev)
690 {
691         struct wavnc_info       *devc = (struct wavnc_info *)
692                                         audio_devs[dev]->devc;
693         unsigned long   flags;
694 
695         spin_lock_irqsave(&waveartist_lock, flags);
696 
697         /*
698          * Stop capture
699          */
700         waveartist_cmd1(devc, WACMD_INPUTSTOP);
701 
702         devc->audio_mode &= ~PCM_ENABLE_INPUT;
703 
704         /*
705          * Clear interrupt by toggling
706          * the IRQ_ACK bit in CTRL
707          */
708         if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
709                 waveartist_iack(devc);
710 
711 //      devc->audio_mode &= ~PCM_ENABLE_INPUT;
712 
713         spin_unlock_irqrestore(&waveartist_lock, flags);
714 }
715 
716 static void
717 waveartist_halt_output(int dev)
718 {
719         struct wavnc_info       *devc = (struct wavnc_info *)
720                                         audio_devs[dev]->devc;
721         unsigned long   flags;
722 
723         spin_lock_irqsave(&waveartist_lock, flags);
724 
725         waveartist_cmd1(devc, WACMD_OUTPUTSTOP);
726 
727         devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
728 
729         /*
730          * Clear interrupt by toggling
731          * the IRQ_ACK bit in CTRL
732          */
733         if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
734                 waveartist_iack(devc);
735 
736 //      devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
737 
738         spin_unlock_irqrestore(&waveartist_lock, flags);
739 }
740 
741 static void
742 waveartist_trigger(int dev, int state)
743 {
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;
748         unsigned long   flags;
749 
750         if (debug_flg & DEBUG_TRIGGER) {
751                 printk("wavnc: audio trigger ");
752                 if (state & PCM_ENABLE_INPUT)
753                         printk("in ");
754                 if (state & PCM_ENABLE_OUTPUT)
755                         printk("out");
756                 printk("\n");
757         }
758 
759         spin_lock_irqsave(&waveartist_lock, flags);
760 
761         state &= devc->audio_mode;
762 
763         if (portc->open_mode & OPEN_READ &&
764             state & PCM_ENABLE_INPUT)
765                 /*
766                  * enable ADC Data Transfer to PC
767                  */
768                 waveartist_cmd1(devc, WACMD_INPUTSTART);
769 
770         if (portc->open_mode & OPEN_WRITE &&
771             state & PCM_ENABLE_OUTPUT)
772                 /*
773                  * enable DAC data transfer from PC
774                  */
775                 waveartist_cmd1(devc, WACMD_OUTPUTSTART);
776 
777         spin_unlock_irqrestore(&waveartist_lock, flags);
778 }
779 
780 static int
781 waveartist_set_speed(int dev, int arg)
782 {
783         struct wavnc_port_info *portc = (struct wavnc_port_info *)
784                                         audio_devs[dev]->portc;
785 
786         if (arg <= 0)
787                 return portc->speed;
788 
789         if (arg < 5000)
790                 arg = 5000;
791         if (arg > 44100)
792                 arg = 44100;
793 
794         portc->speed = arg;
795         return portc->speed;
796 
797 }
798 
799 static short
800 waveartist_set_channels(int dev, short arg)
801 {
802         struct wavnc_port_info *portc = (struct wavnc_port_info *)
803                                         audio_devs[dev]->portc;
804 
805         if (arg != 1 && arg != 2)
806                 return portc->channels;
807 
808         portc->channels = arg;
809         return arg;
810 }
811 
812 static unsigned int
813 waveartist_set_bits(int dev, unsigned int arg)
814 {
815         struct wavnc_port_info *portc = (struct wavnc_port_info *)
816                                         audio_devs[dev]->portc;
817 
818         if (arg == 0)
819                 return portc->audio_format;
820 
821         if ((arg != AFMT_U8) && (arg != AFMT_S16_LE) && (arg != AFMT_S8))
822                 arg = AFMT_U8;
823 
824         portc->audio_format = arg;
825 
826         return arg;
827 }
828 
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
845 };
846 
847 
848 static irqreturn_t
849 waveartist_intr(int irq, void *dev_id)
850 {
851         struct wavnc_info *devc = dev_id;
852         int        irqstatus, status;
853 
854         spin_lock(&waveartist_lock);
855         irqstatus = inb(devc->hw.io_base + IRQSTAT);
856         status    = inb(devc->hw.io_base + STATR);
857 
858         if (debug_flg & DEBUG_INTR)
859                 printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
860                        status, irqstatus);
861 
862         if (status & IRQ_REQ)   /* Clear interrupt */
863                 waveartist_iack(devc);
864         else
865                 printk(KERN_WARNING "waveartist: unexpected interrupt\n");
866 
867         if (irqstatus & 0x01) {
868                 int temp = 1;
869 
870                 /* PCM buffer done
871                  */
872                 if ((status & DMA0) && (devc->audio_mode & PCM_ENABLE_OUTPUT)) {
873                         DMAbuf_outputintr(devc->playback_dev, 1);
874                         temp = 0;
875                 }
876                 if ((status & DMA1) && (devc->audio_mode & PCM_ENABLE_INPUT)) {
877                         DMAbuf_inputintr(devc->record_dev);
878                         temp = 0;
879                 }
880                 if (temp)       //default:
881                         printk(KERN_WARNING "waveartist: Unknown interrupt\n");
882         }
883         if (irqstatus & 0x2)
884                 // We do not use SB mode natively...
885                 printk(KERN_WARNING "waveartist: Unexpected SB interrupt...\n");
886         spin_unlock(&waveartist_lock);
887         return IRQ_HANDLED;
888 }
889 
890 /* -------------------------------------------------------------------------
891  * Mixer stuff
892  */
893 struct mix_ent {
894         unsigned char   reg_l;
895         unsigned char   reg_r;
896         unsigned char   shift;
897         unsigned char   max;
898 };
899 
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   */
912 #if 0
913         { 3, 7, 0, 10 }, /* SOUND_MIXER_RECLEV   */
914         { 0, 0, 0,  0 }, /* SOUND_MIXER_IGAIN    */
915 #else
916         { 0, 0, 0,  0 }, /* SOUND_MIXER_RECLEV   */
917         { 3, 7, 0,  7 }, /* SOUND_MIXER_IGAIN    */
918 #endif
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  */
931 };
932 
933 static void
934 waveartist_mixer_update(struct wavnc_info *devc, int whichDev)
935 {
936         unsigned int lev_left, lev_right;
937 
938         lev_left  = devc->levels[whichDev] & 0xff;
939         lev_right = devc->levels[whichDev] >> 8;
940 
941         if (lev_left > 100)
942                 lev_left = 100;
943         if (lev_right > 100)
944                 lev_right = 100;
945 
946 #define SCALE(lev,max)  ((lev) * (max) / 100)
947 
948         if (machine_is_netwinder() && whichDev == SOUND_MIXER_PHONEOUT)
949                 whichDev = SOUND_MIXER_VOLUME;
950 
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;
954 
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;
958 
959                 /* read left setting */
960                 left  = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
961                                                mix->reg_l << 8);
962 
963                 /* read right setting */
964                 right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
965                                                 mix->reg_r << 8);
966 
967                 left  = (left  & ~mask) | (lev_left  & mask);
968                 right = (right & ~mask) | (lev_right & mask);
969 
970                 /* write left,right back */
971                 waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
972         } else {
973                 switch(whichDev) {
974                 case SOUND_MIXER_PCM:
975                         waveartist_cmd3(devc, WACMD_SET_LEVEL,
976                                         SCALE(lev_left,  32767),
977                                         SCALE(lev_right, 32767));
978                         break;
979 
980                 case SOUND_MIXER_SYNTH:
981                         waveartist_cmd3(devc, 0x0100 | WACMD_SET_LEVEL,
982                                         SCALE(lev_left,  32767),
983                                         SCALE(lev_right, 32767));
984                         break;
985                 }
986         }
987 }
988 
989 /*
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.
993  */
994 static void
995 waveartist_set_adc_mux(struct wavnc_info *devc, char left_dev,
996                        char right_dev)
997 {
998         unsigned int reg_08, reg_09;
999 
1000         reg_08 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0800);
1001         reg_09 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0900);
1002 
1003         reg_08 = (reg_08 & ~0x3f) | right_dev << 3 | left_dev;
1004 
1005         waveartist_cmd3(devc, WACMD_SET_MIXER, reg_08, reg_09);
1006 }
1007 
1008 /*
1009  * Decode a recording mask into a mixer selection as follows:
1010  *
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
1017  */
1018 static unsigned int
1019 waveartist_select_input(struct wavnc_info *devc, unsigned int recmask,
1020                         unsigned char *dev_l, unsigned char *dev_r)
1021 {
1022         unsigned int recdev = ADC_MUX_NONE;
1023 
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;
1039         }
1040 
1041         *dev_l = *dev_r = recdev;
1042 
1043         return recmask;
1044 }
1045 
1046 static int
1047 waveartist_decode_mixer(struct wavnc_info *devc, int dev,
1048                         unsigned char lev_l,
1049                         unsigned char lev_r)
1050 {
1051         switch (dev) {
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;
1061                 break;
1062 
1063         case SOUND_MIXER_IMIX:
1064                 break;
1065 
1066         default:
1067                 dev = -EINVAL;
1068                 break;
1069         }
1070 
1071         return dev;
1072 }
1073 
1074 static int waveartist_get_mixer(struct wavnc_info *devc, int dev)
1075 {
1076         return devc->levels[dev];
1077 }
1078 
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 |
1083                         SOUND_MASK_IMIX,
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,
1089 };
1090 
1091 static void
1092 waveartist_set_recmask(struct wavnc_info *devc, unsigned int recmask)
1093 {
1094         unsigned char dev_l, dev_r;
1095 
1096         recmask &= devc->mix->recording_devs;
1097 
1098         /*
1099          * If more than one recording device selected,
1100          * disable the device that is currently in use.
1101          */
1102         if (hweight32(recmask) > 1)
1103                 recmask &= ~devc->recmask;
1104 
1105         /*
1106          * Translate the recording device mask into
1107          * the ADC multiplexer settings.
1108          */
1109         devc->recmask = devc->mix->select_input(devc, recmask,
1110                                                 &dev_l, &dev_r);
1111 
1112         waveartist_set_adc_mux(devc, dev_l, dev_r);
1113 }
1114 
1115 static int
1116 waveartist_set_mixer(struct wavnc_info *devc, int dev, unsigned int level)
1117 {
1118         unsigned int lev_left  = level & 0x00ff;
1119         unsigned int lev_right = (level & 0xff00) >> 8;
1120 
1121         if (lev_left > 100)
1122                 lev_left = 100;
1123         if (lev_right > 100)
1124                 lev_right = 100;
1125 
1126         /*
1127          * Mono devices have their right volume forced to their
1128          * left volume.  (from ALSA driver OSS emulation).
1129          */
1130         if (!(devc->mix->stereo_devs & (1 << dev)))
1131                 lev_right = lev_left;
1132 
1133         dev = devc->mix->decode_mixer(devc, dev, lev_left, lev_right);
1134 
1135         if (dev >= 0)
1136                 waveartist_mixer_update(devc, dev);
1137 
1138         return dev < 0 ? dev : 0;
1139 }
1140 
1141 static int
1142 waveartist_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
1143 {
1144         struct wavnc_info *devc = (struct wavnc_info *)audio_devs[dev]->devc;
1145         int ret = 0, val, nr;
1146 
1147         /*
1148          * All SOUND_MIXER_* ioctls use type 'M'
1149          */
1150         if (((cmd >> 8) & 255) != 'M')
1151                 return -ENOIOCTLCMD;
1152 
1153 #ifdef CONFIG_ARCH_NETWINDER
1154         if (machine_is_netwinder()) {
1155                 ret = vnc_private_ioctl(dev, cmd, arg);
1156                 if (ret != -ENOIOCTLCMD)
1157                         return ret;
1158                 else
1159                         ret = 0;
1160         }
1161 #endif
1162 
1163         nr = cmd & 0xff;
1164 
1165         if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1166                 if (get_user(val, (int __user *)arg))
1167                         return -EFAULT;
1168 
1169                 switch (nr) {
1170                 case SOUND_MIXER_RECSRC:
1171                         waveartist_set_recmask(devc, val);
1172                         break;
1173 
1174                 default:
1175                         ret = -EINVAL;
1176                         if (nr < SOUND_MIXER_NRDEVICES &&
1177                             devc->mix->supported_devs & (1 << nr))
1178                                 ret = waveartist_set_mixer(devc, nr, val);
1179                 }
1180         }
1181 
1182         if (ret == 0 && _SIOC_DIR(cmd) & _SIOC_READ) {
1183                 ret = -EINVAL;
1184 
1185                 switch (nr) {
1186                 case SOUND_MIXER_RECSRC:
1187                         ret = devc->recmask;
1188                         break;
1189 
1190                 case SOUND_MIXER_DEVMASK:
1191                         ret = devc->mix->supported_devs;
1192                         break;
1193 
1194                 case SOUND_MIXER_STEREODEVS:
1195                         ret = devc->mix->stereo_devs;
1196                         break;
1197 
1198                 case SOUND_MIXER_RECMASK:
1199                         ret = devc->mix->recording_devs;
1200                         break;
1201 
1202                 case SOUND_MIXER_CAPS:
1203                         ret = SOUND_CAP_EXCL_INPUT;
1204                         break;
1205 
1206                 default:
1207                         if (nr < SOUND_MIXER_NRDEVICES)
1208                                 ret = devc->mix->get_mixer(devc, nr);
1209                         break;
1210                 }
1211 
1212                 if (ret >= 0)
1213                         ret = put_user(ret, (int __user *)arg) ? -EFAULT : 0;
1214         }
1215 
1216         return ret;
1217 }
1218 
1219 static struct mixer_operations waveartist_mixer_operations =
1220 {
1221         .owner  = THIS_MODULE,
1222         .id     = "WaveArtist",
1223         .name   = "WaveArtist",
1224         .ioctl  = waveartist_mixer_ioctl
1225 };
1226 
1227 static void
1228 waveartist_mixer_reset(struct wavnc_info *devc)
1229 {
1230         int i;
1231 
1232         if (debug_flg & DEBUG_MIXER)
1233                 printk("%s: mixer_reset\n", devc->hw.name);
1234 
1235         /*
1236          * reset mixer cmd
1237          */
1238         waveartist_cmd1(devc, WACMD_RST_MIXER);
1239 
1240         /*
1241          * set input for ADC to come from 'quiet'
1242          * turn on default modes
1243          */
1244         waveartist_cmd3(devc, WACMD_SET_MIXER, 0x9800, 0xa836);
1245 
1246         /*
1247          * set mixer input select to none, RX filter gains 0 dB
1248          */
1249         waveartist_cmd3(devc, WACMD_SET_MIXER, 0x4c00, 0x8c00);
1250 
1251         /*
1252          * set bit 0 reg 2 to 1 - unmute MonoOut
1253          */
1254         waveartist_cmd3(devc, WACMD_SET_MIXER, 0x2801, 0x6800);
1255 
1256         /* set default input device = internal mic
1257          * current recording device = none
1258          */
1259         waveartist_set_recmask(devc, 0);
1260 
1261         for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1262                 waveartist_mixer_update(devc, i);
1263 }
1264 
1265 static int __init waveartist_init(struct wavnc_info *devc)
1266 {
1267         struct wavnc_port_info *portc;
1268         char rev[3], dev_name[64];
1269         int my_dev;
1270 
1271         if (waveartist_reset(devc))
1272                 return -ENODEV;
1273 
1274         sprintf(dev_name, "%s (%s", devc->hw.name, devc->chip_name);
1275 
1276         if (waveartist_getrev(devc, rev)) {
1277                 strcat(dev_name, " rev. ");
1278                 strcat(dev_name, rev);
1279         }
1280         strcat(dev_name, ")");
1281 
1282         conf_printf2(dev_name, devc->hw.io_base, devc->hw.irq,
1283                      devc->hw.dma, devc->hw.dma2);
1284 
1285         portc = kzalloc(sizeof(struct wavnc_port_info), GFP_KERNEL);
1286         if (portc == NULL)
1287                 goto nomem;
1288 
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);
1293 
1294         if (my_dev < 0)
1295                 goto free;
1296 
1297         audio_devs[my_dev]->portc = portc;
1298 
1299         waveartist_mixer_reset(devc);
1300 
1301         /*
1302          * clear any pending interrupt
1303          */
1304         waveartist_iack(devc);
1305 
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);
1309                 goto uninstall;
1310         }
1311 
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);
1315                 goto uninstall_irq;
1316         }
1317 
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);
1322                         goto uninstall_dma;
1323                 }
1324 
1325         waveartist_set_ctlr(&devc->hw, 0, DMA1_IE | DMA0_IE);
1326 
1327         audio_devs[my_dev]->mixer_dev =
1328                 sound_install_mixer(MIXER_DRIVER_VERSION,
1329                                 dev_name,
1330                                 &waveartist_mixer_operations,
1331                                 sizeof(struct mixer_operations),
1332                                 devc);
1333 
1334         return my_dev;
1335 
1336 uninstall_dma:
1337         sound_free_dma(devc->hw.dma);
1338 
1339 uninstall_irq:
1340         free_irq(devc->hw.irq, devc);
1341 
1342 uninstall:
1343         sound_unload_audiodev(my_dev);
1344 
1345 free:
1346         kfree(portc);
1347 
1348 nomem:
1349         return -1;
1350 }
1351 
1352 static int __init probe_waveartist(struct address_info *hw_config)
1353 {
1354         struct wavnc_info *devc = &adev_info[nr_waveartist_devs];
1355 
1356         if (nr_waveartist_devs >= MAX_AUDIO_DEV) {
1357                 printk(KERN_WARNING "waveartist: too many audio devices\n");
1358                 return 0;
1359         }
1360 
1361         if (!request_region(hw_config->io_base, 15, hw_config->name))  {
1362                 printk(KERN_WARNING "WaveArtist: I/O port conflict\n");
1363                 return 0;
1364         }
1365 
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",
1369                        hw_config->irq);
1370                 return 0;
1371         }
1372 
1373         if (hw_config->dma != 3) {
1374                 release_region(hw_config->io_base, 15);
1375                 printk(KERN_WARNING "WaveArtist: Bad DMA %d\n",
1376                        hw_config->dma);
1377                 return 0;
1378         }
1379 
1380         hw_config->name = "WaveArtist";
1381         devc->hw = *hw_config;
1382         devc->open_mode = 0;
1383         devc->chip_name = "RWA-010";
1384 
1385         return 1;
1386 }
1387 
1388 static void __init
1389 attach_waveartist(struct address_info *hw, const struct waveartist_mixer_info *mix)
1390 {
1391         struct wavnc_info *devc = &adev_info[nr_waveartist_devs];
1392 
1393         /*
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).
1397          */
1398         devc->hw = *hw;
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;
1405 
1406         if (hw->dma != hw->dma2 && hw->dma2 != NO_DMA)
1407                 devc->audio_flags |= DMA_DUPLEX;
1408 
1409         devc->mix = mix;
1410         devc->dev_no = waveartist_init(devc);
1411 
1412         if (devc->dev_no < 0)
1413                 release_region(hw->io_base, 15);
1414         else {
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);
1420 
1421                         vnc_configure_mixer(devc, 0);
1422 
1423                         devc->no_autoselect = 1;
1424                 }
1425 #endif
1426                 nr_waveartist_devs += 1;
1427         }
1428 }
1429 
1430 static void __exit unload_waveartist(struct address_info *hw)
1431 {
1432         struct wavnc_info *devc = NULL;
1433         int i;
1434 
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;
1438                         break;
1439                 }
1440 
1441         if (devc != NULL) {
1442                 int mixer;
1443 
1444 #ifdef CONFIG_ARCH_NETWINDER
1445                 if (machine_is_netwinder())
1446                         del_timer(&vnc_timer);
1447 #endif
1448 
1449                 release_region(devc->hw.io_base, 15);
1450 
1451                 waveartist_set_ctlr(&devc->hw, DMA1_IE|DMA0_IE, 0);
1452 
1453                 if (devc->hw.irq >= 0)
1454                         free_irq(devc->hw.irq, devc);
1455 
1456                 sound_free_dma(devc->hw.dma);
1457 
1458                 if (devc->hw.dma != devc->hw.dma2 &&
1459                     devc->hw.dma2 != NO_DMA)
1460                         sound_free_dma(devc->hw.dma2);
1461 
1462                 mixer = audio_devs[devc->dev_no]->mixer_dev;
1463 
1464                 if (mixer >= 0)
1465                         sound_unload_mixerdev(mixer);
1466 
1467                 if (devc->dev_no >= 0)
1468                         sound_unload_audiodev(devc->dev_no);
1469 
1470                 nr_waveartist_devs -= 1;
1471 
1472                 for (; i < nr_waveartist_devs; i++)
1473                         adev_info[i] = adev_info[i + 1];
1474         } else
1475                 printk(KERN_WARNING "waveartist: can't find device "
1476                        "to unload\n");
1477 }
1478 
1479 #ifdef CONFIG_ARCH_NETWINDER
1480 
1481 /*
1482  * Rebel.com Netwinder specifics...
1483  */
1484 
1485 #include <asm/hardware/dec21285.h>
1486  
1487 #define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
1488 
1489 #define MIXER_PRIVATE3_RESET    0x53570000
1490 #define MIXER_PRIVATE3_READ     0x53570001
1491 #define MIXER_PRIVATE3_WRITE    0x53570002
1492 
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
1498 
1499 static inline void
1500 vnc_mute_spkr(struct wavnc_info *devc)
1501 {
1502         unsigned long flags;
1503 
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);
1507 }
1508 
1509 static void
1510 vnc_mute_lout(struct wavnc_info *devc)
1511 {
1512         unsigned int left, right;
1513 
1514         left  = waveartist_cmd1_r(devc, WACMD_GET_LEVEL);
1515         right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x400);
1516 
1517         if (devc->line_mute_state) {
1518                 left &= ~1;
1519                 right &= ~1;
1520         } else {
1521                 left |= 1;
1522                 right |= 1;
1523         }
1524         waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
1525                 
1526 }
1527 
1528 static int
1529 vnc_volume_slider(struct wavnc_info *devc)
1530 {
1531         static signed int old_slider_volume;
1532         unsigned long flags;
1533         signed int volume = 255;
1534 
1535         *CSR_TIMER1_LOAD = 0x00ffffff;
1536 
1537         spin_lock_irqsave(&waveartist_lock, flags);
1538 
1539         outb(0xFF, 0x201);
1540         *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV1;
1541 
1542         while (volume && (inb(0x201) & 0x01))
1543                 volume--;
1544 
1545         *CSR_TIMER1_CNTL = 0;
1546 
1547         spin_unlock_irqrestore(&waveartist_lock,flags);
1548         
1549         volume = 0x00ffffff - *CSR_TIMER1_VALUE;
1550 
1551 
1552 #ifndef REVERSE
1553         volume = 150 - (volume >> 5);
1554 #else
1555         volume = (volume >> 6) - 25;
1556 #endif
1557 
1558         if (volume < 0)
1559                 volume = 0;
1560 
1561         if (volume > 100)
1562                 volume = 100;
1563 
1564         /*
1565          * slider quite often reads +-8, so debounce this random noise
1566          */
1567         if (abs(volume - old_slider_volume) > 7) {
1568                 old_slider_volume = volume;
1569 
1570                 if (debug_flg & DEBUG_MIXER)
1571                         printk(KERN_DEBUG "Slider volume: %d.\n", volume);
1572         }
1573 
1574         return old_slider_volume;
1575 }
1576 
1577 /*
1578  * Decode a recording mask into a mixer selection on the NetWinder
1579  * as follows:
1580  *
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
1587  */
1588 static unsigned int
1589 netwinder_select_input(struct wavnc_info *devc, unsigned int recmask,
1590                        unsigned char *dev_l, unsigned char *dev_r)
1591 {
1592         unsigned int recdev_l = ADC_MUX_NONE, recdev_r = ADC_MUX_NONE;
1593 
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;
1617         }
1618 
1619         *dev_l = recdev_l;
1620         *dev_r = recdev_r;
1621 
1622         return recmask;
1623 }
1624 
1625 static int
1626 netwinder_decode_mixer(struct wavnc_info *devc, int dev, unsigned char lev_l,
1627                        unsigned char lev_r)
1628 {
1629         switch (dev) {
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;
1636                 break;
1637 
1638         case SOUND_MIXER_MIC:           /* right mic only */
1639                 devc->levels[SOUND_MIXER_MIC] &= 0xff;
1640                 devc->levels[SOUND_MIXER_MIC] |= lev_l << 8;
1641                 break;
1642 
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;
1647                 break;
1648 
1649         case SOUND_MIXER_PHONEIN:       /* left aux only  */
1650                 devc->levels[SOUND_MIXER_LINE1] = lev_l;
1651                 dev = SOUND_MIXER_LINE1;
1652                 break;
1653 
1654         case SOUND_MIXER_IMIX:
1655         case SOUND_MIXER_PHONEOUT:
1656                 break;
1657 
1658         default:
1659                 dev = -EINVAL;
1660                 break;
1661         }
1662         return dev;
1663 }
1664 
1665 static int netwinder_get_mixer(struct wavnc_info *devc, int dev)
1666 {
1667         int levels;
1668 
1669         switch (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];
1676                 break;
1677 
1678         case SOUND_MIXER_MIC:           /* builtin mic: right mic only */
1679                 levels = devc->levels[SOUND_MIXER_MIC] >> 8;
1680                 levels |= levels << 8;
1681                 break;
1682 
1683         case SOUND_MIXER_LINE1:         /* handset mic: left mic only */
1684                 levels = devc->levels[SOUND_MIXER_MIC] & 0xff;
1685                 levels |= levels << 8;
1686                 break;
1687 
1688         case SOUND_MIXER_PHONEIN:       /* phone mic: left aux1 only */
1689                 levels = devc->levels[SOUND_MIXER_LINE1] & 0xff;
1690                 levels |= levels << 8;
1691                 break;
1692 
1693         default:
1694                 levels = 0;
1695         }
1696 
1697         return levels;
1698 }
1699 
1700 /*
1701  * Waveartist specific mixer information.
1702  */
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|
1709                         SOUND_MASK_IGAIN,
1710 
1711         .recording_devs = SOUND_MASK_LINE    | SOUND_MASK_MIC     |
1712                         SOUND_MASK_IMIX    | SOUND_MASK_LINE1   |
1713                         SOUND_MASK_PHONEIN,
1714 
1715         .stereo_devs    = SOUND_MASK_VOLUME  | SOUND_MASK_SYNTH   |
1716                         SOUND_MASK_PCM     | SOUND_MASK_LINE    |
1717                         SOUND_MASK_IMIX    | SOUND_MASK_IGAIN,
1718 
1719         .select_input   = netwinder_select_input,
1720         .decode_mixer   = netwinder_decode_mixer,
1721         .get_mixer      = netwinder_get_mixer,
1722 };
1723 
1724 static void
1725 vnc_configure_mixer(struct wavnc_info *devc, unsigned int recmask)
1726 {
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;
1734                 } else {
1735                         /* unless someone has asked for LINE-IN,
1736                          * we default to MIC
1737                          */
1738                         if ((devc->recmask & SOUND_MASK_LINE) == 0)
1739                                 devc->recmask = SOUND_MASK_MIC;
1740                         devc->spkr_mute_state = devc->line_mute_state = 0;
1741                 }
1742                 vnc_mute_spkr(devc);
1743                 vnc_mute_lout(devc);
1744 
1745                 if (recmask != devc->recmask)
1746                         waveartist_set_recmask(devc, recmask);
1747         }
1748 }
1749 
1750 static int
1751 vnc_slider(struct wavnc_info *devc)
1752 {
1753         signed int slider_volume;
1754         unsigned int temp, old_hs, old_td;
1755 
1756         /*
1757          * read the "buttons" state.
1758          *  Bit 4 = 0 means handset present
1759          *  Bit 5 = 1 means phone offhook
1760          */
1761         temp = inb(0x201);
1762 
1763         old_hs = devc->handset_detect;
1764         old_td = devc->telephone_detect;
1765 
1766         devc->handset_detect = !(temp & 0x10);
1767         devc->telephone_detect = !!(temp & 0x20);
1768 
1769         if (!devc->no_autoselect &&
1770             (old_hs != devc->handset_detect ||
1771              old_td != devc->telephone_detect))
1772                 vnc_configure_mixer(devc, devc->recmask);
1773 
1774         slider_volume = vnc_volume_slider(devc);
1775 
1776         /*
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.
1780          */
1781         if (abs(devc->slider_vol - slider_volume) > 20)
1782                 devc->use_slider = 1;
1783 
1784         /*
1785          * use only left channel
1786          */
1787         temp = levels[SOUND_MIXER_VOLUME] & 0xFF;
1788 
1789         if (slider_volume != temp && devc->use_slider) {
1790                 devc->slider_vol = slider_volume;
1791 
1792                 waveartist_set_mixer(devc, SOUND_MIXER_VOLUME,
1793                         slider_volume | slider_volume << 8);
1794 
1795                 return 1;
1796         }
1797 
1798         return 0;
1799 }
1800 
1801 static void
1802 vnc_slider_tick(unsigned long data)
1803 {
1804         int next_timeout;
1805 
1806         if (vnc_slider(adev_info + data))
1807                 next_timeout = 5;       // mixer reported change
1808         else
1809                 next_timeout = VNC_TIMER_PERIOD;
1810 
1811         mod_timer(&vnc_timer, jiffies + next_timeout);
1812 }
1813 
1814 static int
1815 vnc_private_ioctl(int dev, unsigned int cmd, int __user * arg)
1816 {
1817         struct wavnc_info *devc = (struct wavnc_info *)audio_devs[dev]->devc;
1818         int val;
1819 
1820         switch (cmd) {
1821         case SOUND_MIXER_PRIVATE1:
1822         {
1823                 u_int prev_spkr_mute, prev_line_mute, prev_auto_state;
1824                 int val;
1825 
1826                 if (get_user(val, arg))
1827                         return -EFAULT;
1828 
1829                 /* check if parameter is logical */
1830                 if (val & ~(VNC_MUTE_INTERNAL_SPKR |
1831                             VNC_MUTE_LINE_OUT |
1832                             VNC_DISABLE_AUTOSWITCH))
1833                         return -EINVAL;
1834 
1835                 prev_auto_state = devc->no_autoselect;
1836                 prev_spkr_mute  = devc->spkr_mute_state;
1837                 prev_line_mute  = devc->line_mute_state;
1838 
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;
1842 
1843                 if (prev_spkr_mute != devc->spkr_mute_state)
1844                         vnc_mute_spkr(devc);
1845 
1846                 if (prev_line_mute != devc->line_mute_state)
1847                         vnc_mute_lout(devc);
1848 
1849                 if (prev_auto_state != devc->no_autoselect)
1850                         vnc_configure_mixer(devc, devc->recmask);
1851 
1852                 return 0;
1853         }
1854 
1855         case SOUND_MIXER_PRIVATE2:
1856                 if (get_user(val, arg))
1857                         return -EFAULT;
1858 
1859                 switch (val) {
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);
1864                         break;
1865 
1866                 case VNC_SOUND_RESUME:
1867                         waveartist_cmd1(devc, 0x18);
1868                         break;
1869 
1870                 default:
1871                         return -EINVAL;
1872                 }
1873                 return 0;
1874 
1875         /* private ioctl to allow bulk access to waveartist */
1876         case SOUND_MIXER_PRIVATE3:
1877         {
1878                 unsigned long   flags;
1879                 int             mixer_reg[15], i, val;
1880 
1881                 if (get_user(val, arg))
1882                         return -EFAULT;
1883                 if (copy_from_user(mixer_reg, (void *)val, sizeof(mixer_reg)))
1884                         return -EFAULT;
1885 
1886                 switch (mixer_reg[14]) {
1887                 case MIXER_PRIVATE3_RESET:
1888                         waveartist_mixer_reset(devc);
1889                         break;
1890 
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]);
1897 
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]);
1900                         break;
1901 
1902                 case MIXER_PRIVATE3_READ:
1903                         spin_lock_irqsave(&waveartist_lock, flags);
1904 
1905                         for (i = 0x30; i < 14 << 8; i += 1 << 8)
1906                                 waveartist_cmd(devc, 1, &i, 1, mixer_reg + (i >> 8));
1907 
1908                         spin_unlock_irqrestore(&waveartist_lock, flags);
1909 
1910                         if (copy_to_user((void *)val, mixer_reg, sizeof(mixer_reg)))
1911                                 return -EFAULT;
1912                         break;
1913 
1914                 default:
1915                         return -EINVAL;
1916                 }
1917                 return 0;
1918         }
1919 
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);
1927 
1928                 return put_user(val, arg) ? -EFAULT : 0;
1929         }
1930 
1931         if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1932                 /*
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
1938                  * hardware...
1939                  */
1940                 if ((cmd & 0xff) == SOUND_MIXER_VOLUME)
1941                         devc->use_slider = 0;
1942 
1943                 /* speaker output            */
1944                 if ((cmd & 0xff) == SOUND_MIXER_SPEAKER) {
1945                         unsigned int val, l, r;
1946 
1947                         if (get_user(val, arg))
1948                                 return -EFAULT;
1949 
1950                         l = val & 0x7f;
1951                         r = (val & 0x7f00) >> 8;
1952                         val = (l + r) / 2;
1953                         devc->levels[SOUND_MIXER_SPEAKER] = val | (val << 8);
1954                         devc->spkr_mute_state = (val <= 50);
1955                         vnc_mute_spkr(devc);
1956                         return 0;
1957                 }
1958         }
1959 
1960         return -ENOIOCTLCMD;
1961 }
1962 
1963 #endif
1964 
1965 static struct address_info cfg;
1966 
1967 static int attached;
1968 
1969 static int __initdata io = 0;
1970 static int __initdata irq = 0;
1971 static int __initdata dma = 0;
1972 static int __initdata dma2 = 0;
1973 
1974 
1975 static int __init init_waveartist(void)
1976 {
1977         const struct waveartist_mixer_info *mix;
1978 
1979         if (!io && machine_is_netwinder()) {
1980                 /*
1981                  * The NetWinder WaveArtist is at a fixed address.
1982                  * If the user does not supply an address, use the
1983                  * well-known parameters.
1984                  */
1985                 io   = 0x250;
1986                 irq  = 12;
1987                 dma  = 3;
1988                 dma2 = 7;
1989         }
1990 
1991         mix = &waveartist_mixer;
1992 #ifdef CONFIG_ARCH_NETWINDER
1993         if (machine_is_netwinder())
1994                 mix = &netwinder_mixer;
1995 #endif
1996 
1997         cfg.io_base = io;
1998         cfg.irq = irq;
1999         cfg.dma = dma;
2000         cfg.dma2 = dma2;
2001 
2002         if (!probe_waveartist(&cfg))
2003                 return -ENODEV;
2004 
2005         attach_waveartist(&cfg, mix);
2006         attached = 1;
2007 
2008         return 0;
2009 }
2010 
2011 static void __exit cleanup_waveartist(void)
2012 {
2013         if (attached)
2014                 unload_waveartist(&cfg);
2015 }
2016 
2017 module_init(init_waveartist);
2018 module_exit(cleanup_waveartist);
2019 
2020 #ifndef MODULE
2021 static int __init setup_waveartist(char *str)
2022 {
2023         /* io, irq, dma, dma2 */
2024         int ints[5];
2025         
2026         str = get_options(str, ARRAY_SIZE(ints), ints);
2027         
2028         io      = ints[1];
2029         irq     = ints[2];
2030         dma     = ints[3];
2031         dma2    = ints[4];
2032 
2033         return 1;
2034 }
2035 __setup("waveartist=", setup_waveartist);
2036 #endif
2037 
2038 MODULE_DESCRIPTION("Rockwell WaveArtist RWA-010 sound driver");
2039 module_param_hw(io, int, ioport, 0);            /* IO base */
2040 module_param_hw(irq, int, irq, 0);              /* IRQ */
2041 module_param_hw(dma, int, dma, 0);              /* DMA */
2042 module_param_hw(dma2, int, dma, 0);             /* DMA2 */
2043 MODULE_LICENSE("GPL");
2044 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp