2 * forte.c - ForteMedia FM801 OSS Driver
4 * Written by Martin K. Petersen <mkp@mkp.net>
5 * Copyright (C) 2002 Hewlett-Packard Company
6 * Portions Copyright (C) 2003 Martin K. Petersen
8 * Latest version: http://mkp.net/forte/
10 * Based upon the ALSA FM801 driver by Jaroslav Kysela and OSS drivers
11 * by Thomas Sailer, Alan Cox, Zach Brown, and Jeff Garzik. Thanks
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License version
16 * 2 as published by the Free Software Foundation.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/spinlock.h>
36 #include <linux/pci.h>
38 #include <linux/delay.h>
39 #include <linux/poll.h>
41 #include <linux/sound.h>
42 #include <linux/ac97_codec.h>
43 #include <linux/interrupt.h>
45 #include <linux/proc_fs.h>
47 #include <asm/uaccess.h>
48 #include <asm/hardirq.h>
51 #define DRIVER_NAME "forte"
52 #define DRIVER_VERSION "$Id: forte.c,v 1.63 2003/03/01 05:32:42 mkp Exp $"
53 #define PFX DRIVER_NAME ": "
58 #define DPRINTK(args...) printk(KERN_WARNING args)
60 #define DPRINTK(args...)
63 /* Card capabilities */
64 #define FORTE_CAPS (DSP_CAP_MMAP | DSP_CAP_TRIGGER)
66 /* Supported audio formats */
67 #define FORTE_FMTS (AFMT_U8 | AFMT_S16_LE)
70 #define FORTE_MIN_FRAG_SIZE 256
71 #define FORTE_MAX_FRAG_SIZE PAGE_SIZE
72 #define FORTE_DEF_FRAG_SIZE 256
73 #define FORTE_MIN_FRAGMENTS 2
74 #define FORTE_MAX_FRAGMENTS 256
75 #define FORTE_DEF_FRAGMENTS 2
76 #define FORTE_MIN_BUF_MSECS 500
77 #define FORTE_MAX_BUF_MSECS 1000
80 #define FORTE_PCM_VOL 0x00 /* PCM Output Volume */
81 #define FORTE_FM_VOL 0x02 /* FM Output Volume */
82 #define FORTE_I2S_VOL 0x04 /* I2S Volume */
83 #define FORTE_REC_SRC 0x06 /* Record Source */
84 #define FORTE_PLY_CTRL 0x08 /* Playback Control */
85 #define FORTE_PLY_COUNT 0x0a /* Playback Count */
86 #define FORTE_PLY_BUF1 0x0c /* Playback Buffer I */
87 #define FORTE_PLY_BUF2 0x10 /* Playback Buffer II */
88 #define FORTE_CAP_CTRL 0x14 /* Capture Control */
89 #define FORTE_CAP_COUNT 0x16 /* Capture Count */
90 #define FORTE_CAP_BUF1 0x18 /* Capture Buffer I */
91 #define FORTE_CAP_BUF2 0x1c /* Capture Buffer II */
92 #define FORTE_CODEC_CTRL 0x22 /* Codec Control */
93 #define FORTE_I2S_MODE 0x24 /* I2S Mode Control */
94 #define FORTE_VOLUME 0x26 /* Volume Up/Down/Mute Status */
95 #define FORTE_I2C_CTRL 0x29 /* I2C Control */
96 #define FORTE_AC97_CMD 0x2a /* AC'97 Command */
97 #define FORTE_AC97_DATA 0x2c /* AC'97 Data */
98 #define FORTE_MPU401_DATA 0x30 /* MPU401 Data */
99 #define FORTE_MPU401_CMD 0x31 /* MPU401 Command */
100 #define FORTE_GPIO_CTRL 0x52 /* General Purpose I/O Control */
101 #define FORTE_GEN_CTRL 0x54 /* General Control */
102 #define FORTE_IRQ_MASK 0x56 /* Interrupt Mask */
103 #define FORTE_IRQ_STATUS 0x5a /* Interrupt Status */
104 #define FORTE_OPL3_BANK0 0x68 /* OPL3 Status Read / Bank 0 Write */
105 #define FORTE_OPL3_DATA0 0x69 /* OPL3 Data 0 Write */
106 #define FORTE_OPL3_BANK1 0x6a /* OPL3 Bank 1 Write */
107 #define FORTE_OPL3_DATA1 0x6b /* OPL3 Bank 1 Write */
108 #define FORTE_POWERDOWN 0x70 /* Blocks Power Down Control */
110 #define FORTE_CAP_OFFSET FORTE_CAP_CTRL - FORTE_PLY_CTRL
112 #define FORTE_AC97_ADDR_SHIFT 10
114 /* Playback and record control register bits */
115 #define FORTE_BUF1_LAST (1<<1)
116 #define FORTE_BUF2_LAST (1<<2)
117 #define FORTE_START (1<<5)
118 #define FORTE_PAUSE (1<<6)
119 #define FORTE_IMMED_STOP (1<<7)
120 #define FORTE_RATE_SHIFT 8
121 #define FORTE_RATE_MASK (15 << FORTE_RATE_SHIFT)
122 #define FORTE_CHANNELS_4 (1<<12) /* Playback only */
123 #define FORTE_CHANNELS_6 (2<<12) /* Playback only */
124 #define FORTE_CHANNELS_6MS (3<<12) /* Playback only */
125 #define FORTE_CHANNELS_MASK (3<<12)
126 #define FORTE_16BIT (1<<14)
127 #define FORTE_STEREO (1<<15)
129 /* IRQ status bits */
130 #define FORTE_IRQ_PLAYBACK (1<<8)
131 #define FORTE_IRQ_CAPTURE (1<<9)
132 #define FORTE_IRQ_VOLUME (1<<14)
133 #define FORTE_IRQ_MPU (1<<15)
136 #define FORTE_CC_CODEC_RESET (1<<5)
137 #define FORTE_CC_AC97_RESET (1<<6)
140 #define FORTE_AC97_WRITE (0<<7)
141 #define FORTE_AC97_READ (1<<7)
142 #define FORTE_AC97_DP_INVALID (0<<8)
143 #define FORTE_AC97_DP_VALID (1<<8)
144 #define FORTE_AC97_PORT_RDY (0<<9)
145 #define FORTE_AC97_PORT_BSY (1<<9)
148 struct forte_channel {
151 unsigned short ctrl; /* Ctrl BAR contents */
152 unsigned long iobase; /* Ctrl BAR address */
154 wait_queue_head_t wait;
156 void *buf; /* Buffer */
157 dma_addr_t buf_handle; /* Buffer handle */
164 unsigned int frag_sz; /* Current fragment size */
165 unsigned int frag_num; /* Current # of fragments */
166 unsigned int frag_msecs; /* Milliseconds per frag */
167 unsigned int buf_sz; /* Current buffer size */
169 unsigned int hwptr; /* Tail */
170 unsigned int swptr; /* Head */
171 unsigned int filled_frags; /* Fragments currently full */
172 unsigned int next_buf; /* Index of next buffer */
174 unsigned int active; /* Channel currently in use */
175 unsigned int mapped; /* mmap */
177 unsigned int buf_pages; /* Real size of buffer */
178 unsigned int nr_irqs; /* Number of interrupts */
179 unsigned int bytes; /* Total bytes */
180 unsigned int residue; /* Partial fragment */
185 struct pci_dev *pci_dev;
186 unsigned long iobase;
189 struct semaphore open_sem; /* Device access */
190 spinlock_t lock; /* State */
192 spinlock_t ac97_lock;
193 struct ac97_codec *ac97;
196 int dsp; /* OSS handle */
197 int trigger; /* mmap I/O trigger */
199 struct forte_channel play;
200 struct forte_channel rec;
204 static int channels[] = { 2, 4, 6, };
205 static int rates[] = { 5500, 8000, 9600, 11025, 16000, 19200,
206 22050, 32000, 38400, 44100, 48000, };
208 static struct forte_chip *forte;
212 /* AC97 Codec -------------------------------------------------------------- */
217 * @chip: fm801 instance whose AC97 codec to wait on
224 forte_ac97_wait (struct forte_chip *chip)
228 while ( (inw (chip->iobase + FORTE_AC97_CMD) & FORTE_AC97_PORT_BSY)
238 * @codec: AC97 codec to read from
239 * @reg: register to read
243 forte_ac97_read (struct ac97_codec *codec, u8 reg)
246 struct forte_chip *chip = codec->private_data;
248 spin_lock (&chip->ac97_lock);
251 if (forte_ac97_wait (chip)) {
252 printk (KERN_ERR PFX "ac97_read: Serial bus busy\n");
256 /* Send read command */
257 outw (reg | (1<<7), chip->iobase + FORTE_AC97_CMD);
259 if (forte_ac97_wait (chip)) {
260 printk (KERN_ERR PFX "ac97_read: Bus busy reading reg 0x%x\n",
265 /* Sanity checking */
266 if (inw (chip->iobase + FORTE_AC97_CMD) & FORTE_AC97_DP_INVALID) {
267 printk (KERN_ERR PFX "ac97_read: Invalid data port");
272 ret = inw (chip->iobase + FORTE_AC97_DATA);
275 spin_unlock (&chip->ac97_lock);
282 * @codec: AC97 codec to send command to
283 * @reg: register to write
284 * @val: value to write
288 forte_ac97_write (struct ac97_codec *codec, u8 reg, u16 val)
290 struct forte_chip *chip = codec->private_data;
292 spin_lock (&chip->ac97_lock);
295 if (forte_ac97_wait (chip)) {
296 printk (KERN_ERR PFX "ac97_write: Serial bus busy\n");
300 outw (val, chip->iobase + FORTE_AC97_DATA);
301 outb (reg | FORTE_AC97_WRITE, chip->iobase + FORTE_AC97_CMD);
303 /* Wait for completion */
304 if (forte_ac97_wait (chip)) {
305 printk (KERN_ERR PFX "ac97_write: Bus busy after write\n");
310 spin_unlock (&chip->ac97_lock);
314 /* Mixer ------------------------------------------------------------------- */
324 forte_mixer_open (struct inode *inode, struct file *file)
326 struct forte_chip *chip = forte;
327 file->private_data = chip->ac97;
333 * forte_mixer_release:
339 forte_mixer_release (struct inode *inode, struct file *file)
341 /* We will welease Wodewick */
353 forte_mixer_ioctl (struct inode *inode, struct file *file,
354 unsigned int cmd, unsigned long arg)
356 struct ac97_codec *codec = (struct ac97_codec *) file->private_data;
358 return codec->mixer_ioctl (codec, cmd, arg);
362 static struct file_operations forte_mixer_fops = {
363 .owner = THIS_MODULE,
365 .ioctl = forte_mixer_ioctl,
366 .open = forte_mixer_open,
367 .release = forte_mixer_release,
371 /* Channel ----------------------------------------------------------------- */
374 * forte_channel_reset:
375 * @channel: Channel to reset
377 * Locking: Must be called with lock held.
381 forte_channel_reset (struct forte_channel *channel)
383 if (!channel || !channel->iobase)
386 DPRINTK ("%s: channel = %s\n", __FUNCTION__, channel->name);
388 channel->ctrl &= ~FORTE_START;
389 outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
391 /* We always play at least two fragments, hence these defaults */
392 channel->hwptr = channel->frag_sz;
393 channel->next_buf = 1;
395 channel->filled_frags = 0;
398 channel->nr_irqs = 0;
400 channel->residue = 0;
405 * forte_channel_start:
406 * @channel: Channel to start (record/playback)
408 * Locking: Must be called with lock held.
412 forte_channel_start (struct forte_channel *channel)
414 if (!channel || !channel->iobase || channel->active)
417 channel->ctrl &= ~(FORTE_PAUSE | FORTE_BUF1_LAST | FORTE_BUF2_LAST
419 channel->ctrl |= FORTE_START;
421 outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
426 * forte_channel_stop:
427 * @channel: Channel to stop
429 * Locking: Must be called with lock held.
433 forte_channel_stop (struct forte_channel *channel)
435 if (!channel || !channel->iobase)
438 channel->ctrl &= ~(FORTE_START | FORTE_PAUSE);
439 channel->ctrl |= FORTE_IMMED_STOP;
442 outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
447 * forte_channel_pause:
448 * @channel: Channel to pause
450 * Locking: Must be called with lock held.
454 forte_channel_pause (struct forte_channel *channel)
456 if (!channel || !channel->iobase)
459 channel->ctrl |= FORTE_PAUSE;
462 outw (channel->ctrl, channel->iobase + FORTE_PLY_CTRL);
467 * forte_channel_rate:
468 * @channel: Channel whose rate to set. Playback and record are
470 * @rate: Channel rate in Hz
472 * Locking: Must be called with lock held.
476 forte_channel_rate (struct forte_channel *channel, unsigned int rate)
480 if (!channel || !channel->iobase)
483 /* The FM801 only supports a handful of fixed frequencies.
484 * We find the value closest to what userland requested.
486 if (rate <= 6250) { rate = 5500; new_rate = 0; }
487 else if (rate <= 8800) { rate = 8000; new_rate = 1; }
488 else if (rate <= 10312) { rate = 9600; new_rate = 2; }
489 else if (rate <= 13512) { rate = 11025; new_rate = 3; }
490 else if (rate <= 17600) { rate = 16000; new_rate = 4; }
491 else if (rate <= 20625) { rate = 19200; new_rate = 5; }
492 else if (rate <= 27025) { rate = 22050; new_rate = 6; }
493 else if (rate <= 35200) { rate = 32000; new_rate = 7; }
494 else if (rate <= 41250) { rate = 38400; new_rate = 8; }
495 else if (rate <= 46050) { rate = 44100; new_rate = 9; }
496 else { rate = 48000; new_rate = 10; }
498 channel->ctrl &= ~FORTE_RATE_MASK;
499 channel->ctrl |= new_rate << FORTE_RATE_SHIFT;
500 channel->rate = rate;
502 DPRINTK ("%s: %s rate = %d\n", __FUNCTION__, channel->name, rate);
509 * forte_channel_format:
510 * @channel: Channel whose audio format to set
511 * @format: OSS format ID
513 * Locking: Must be called with lock held.
517 forte_channel_format (struct forte_channel *channel, int format)
519 if (!channel || !channel->iobase)
528 channel->ctrl &= ~FORTE_16BIT;
529 channel->format = AFMT_U8;
534 channel->ctrl |= FORTE_16BIT;
535 channel->format = AFMT_S16_LE;
539 DPRINTK ("%s: %s want %d format, got %d\n", __FUNCTION__, channel->name,
540 format, channel->format);
542 return channel->format;
547 * forte_channel_stereo:
548 * @channel: Channel to toggle
549 * @stereo: 0 for Mono, 1 for Stereo
551 * Locking: Must be called with lock held.
555 forte_channel_stereo (struct forte_channel *channel, unsigned int stereo)
559 if (!channel || !channel->iobase)
562 DPRINTK ("%s: %s stereo = %d\n", __FUNCTION__, channel->name, stereo);
567 channel->ctrl &= ~(FORTE_STEREO | FORTE_CHANNELS_MASK);
568 channel-> stereo = stereo;
573 channel->ctrl &= ~FORTE_CHANNELS_MASK;
574 channel->ctrl |= FORTE_STEREO;
575 channel-> stereo = stereo;
580 DPRINTK ("Unsupported channel format");
590 * forte_channel_buffer:
591 * @channel: Channel whose buffer to set up
593 * Locking: Must be called with lock held.
597 forte_channel_buffer (struct forte_channel *channel, int sz, int num)
599 unsigned int msecs, shift;
601 /* Go away, I'm busy */
602 if (channel->filled_frags || channel->bytes)
605 /* Fragment size must be a power of 2 */
609 channel->frag_sz = 1 << shift;
611 /* Round fragment size to something reasonable */
612 if (channel->frag_sz < FORTE_MIN_FRAG_SIZE)
613 channel->frag_sz = FORTE_MIN_FRAG_SIZE;
615 if (channel->frag_sz > FORTE_MAX_FRAG_SIZE)
616 channel->frag_sz = FORTE_MAX_FRAG_SIZE;
618 /* Find fragment length in milliseconds */
619 msecs = channel->frag_sz /
620 (channel->format == AFMT_S16_LE ? 2 : 1) /
621 (channel->stereo ? 2 : 1) /
622 (channel->rate / 1000);
624 channel->frag_msecs = msecs;
626 /* Pick a suitable number of fragments */
627 if (msecs * num < FORTE_MIN_BUF_MSECS)
628 num = FORTE_MIN_BUF_MSECS / msecs;
630 if (msecs * num > FORTE_MAX_BUF_MSECS)
631 num = FORTE_MAX_BUF_MSECS / msecs;
633 /* Fragment number must be a power of 2 */
637 channel->frag_num = 1 << (shift + 1);
639 /* Round fragment number to something reasonable */
640 if (channel->frag_num < FORTE_MIN_FRAGMENTS)
641 channel->frag_num = FORTE_MIN_FRAGMENTS;
643 if (channel->frag_num > FORTE_MAX_FRAGMENTS)
644 channel->frag_num = FORTE_MAX_FRAGMENTS;
646 channel->buf_sz = channel->frag_sz * channel->frag_num;
648 DPRINTK ("%s: %s frag_sz = %d, frag_num = %d, buf_sz = %d\n",
649 __FUNCTION__, channel->name, channel->frag_sz,
650 channel->frag_num, channel->buf_sz);
655 * forte_channel_prep:
656 * @channel: Channel whose buffer to prepare
658 * Locking: Lock held.
662 forte_channel_prep (struct forte_channel *channel)
670 forte_channel_buffer (channel, channel->frag_sz, channel->frag_num);
671 channel->buf_pages = channel->buf_sz >> PAGE_SHIFT;
673 if (channel->buf_sz % PAGE_SIZE)
674 channel->buf_pages++;
676 DPRINTK ("%s: %s frag_sz = %d, frag_num = %d, buf_sz = %d, pg = %d\n",
677 __FUNCTION__, channel->name, channel->frag_sz,
678 channel->frag_num, channel->buf_sz, channel->buf_pages);
681 channel->buf = pci_alloc_consistent (forte->pci_dev,
682 channel->buf_pages * PAGE_SIZE,
683 &channel->buf_handle);
685 if (!channel->buf || !channel->buf_handle)
688 page = virt_to_page (channel->buf);
690 /* FIXME: can this go away ? */
691 for (i = 0 ; i < channel->buf_pages ; i++)
692 SetPageReserved(page++);
694 /* Prep buffer registers */
695 outw (channel->frag_sz - 1, channel->iobase + FORTE_PLY_COUNT);
696 outl (channel->buf_handle, channel->iobase + FORTE_PLY_BUF1);
697 outl (channel->buf_handle + channel->frag_sz,
698 channel->iobase + FORTE_PLY_BUF2);
701 channel->hwptr = channel->frag_sz;
702 channel->next_buf = 1;
704 DPRINTK ("%s: %s buffer @ %p (%p)\n", __FUNCTION__, channel->name,
705 channel->buf, channel->buf_handle);
710 * forte_channel_drain:
714 * Locking: Don't hold the lock.
718 forte_channel_drain (struct forte_channel *channel)
720 DECLARE_WAITQUEUE (wait, current);
723 DPRINTK ("%s\n", __FUNCTION__);
725 if (channel->mapped) {
726 spin_lock_irqsave (&forte->lock, flags);
727 forte_channel_stop (channel);
728 spin_unlock_irqrestore (&forte->lock, flags);
732 spin_lock_irqsave (&forte->lock, flags);
733 add_wait_queue (&channel->wait, &wait);
736 if (channel->active == 0 || channel->filled_frags == 1)
739 spin_unlock_irqrestore (&forte->lock, flags);
741 __set_current_state (TASK_INTERRUPTIBLE);
744 spin_lock_irqsave (&forte->lock, flags);
747 forte_channel_stop (channel);
748 forte_channel_reset (channel);
749 set_current_state (TASK_RUNNING);
750 remove_wait_queue (&channel->wait, &wait);
751 spin_unlock_irqrestore (&forte->lock, flags);
758 * forte_channel_init:
759 * @chip: Forte chip instance the channel hangs off
760 * @channel: Channel to initialize
763 * Initializes a channel, sets defaults, and allocates
766 * Locking: No lock held.
770 forte_channel_init (struct forte_chip *chip, struct forte_channel *channel)
772 DPRINTK ("%s: chip iobase @ %p\n", __FUNCTION__, (void *)chip->iobase);
774 spin_lock_irq (&chip->lock);
775 memset (channel, 0x0, sizeof (*channel));
777 if (channel == &chip->play) {
778 channel->name = "PCM_OUT";
779 channel->iobase = chip->iobase;
780 DPRINTK ("%s: PCM-OUT iobase @ %p\n", __FUNCTION__,
781 (void *) channel->iobase);
783 else if (channel == &chip->rec) {
784 channel->name = "PCM_IN";
785 channel->iobase = chip->iobase + FORTE_CAP_OFFSET;
787 DPRINTK ("%s: PCM-IN iobase @ %p\n", __FUNCTION__,
788 (void *) channel->iobase);
793 init_waitqueue_head (&channel->wait);
795 /* Defaults: 48kHz, 16-bit, stereo */
796 channel->ctrl = inw (channel->iobase + FORTE_PLY_CTRL);
797 forte_channel_reset (channel);
798 forte_channel_stereo (channel, 1);
799 forte_channel_format (channel, AFMT_S16_LE);
800 forte_channel_rate (channel, 48000);
801 channel->frag_sz = FORTE_DEF_FRAG_SIZE;
802 channel->frag_num = FORTE_DEF_FRAGMENTS;
805 spin_unlock_irq (&chip->lock);
812 * forte_channel_free:
813 * @chip: Chip this channel hangs off
814 * @channel: Channel to nuke
817 * Resets channel and frees buffers.
819 * Locking: Hold your horses.
823 forte_channel_free (struct forte_chip *chip, struct forte_channel *channel)
825 DPRINTK ("%s: %s\n", __FUNCTION__, channel->name);
827 if (!channel->buf_handle)
830 pci_free_consistent (chip->pci_dev, channel->buf_pages * PAGE_SIZE,
831 channel->buf, channel->buf_handle);
833 memset (channel, 0x0, sizeof (*channel));
837 /* DSP --------------------------------------------------------------------- */
845 forte_dsp_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
848 int ival=0, ret, rval=0, rd, wr, count;
849 struct forte_chip *chip;
850 struct audio_buf_info abi;
851 struct count_info cinfo;
853 chip = file->private_data;
855 if (file->f_mode & FMODE_WRITE)
860 if (file->f_mode & FMODE_READ)
868 return put_user (SOUND_VERSION, (int *) arg);
870 case SNDCTL_DSP_GETCAPS:
871 DPRINTK ("%s: GETCAPS\n", __FUNCTION__);
873 ival = FORTE_CAPS; /* DUPLEX */
874 return put_user (ival, (int *) arg);
876 case SNDCTL_DSP_GETFMTS:
877 DPRINTK ("%s: GETFMTS\n", __FUNCTION__);
879 ival = FORTE_FMTS; /* U8, 16LE */
880 return put_user (ival, (int *) arg);
882 case SNDCTL_DSP_SETFMT: /* U8, 16LE */
883 DPRINTK ("%s: SETFMT\n", __FUNCTION__);
885 if (get_user (ival, (int *) arg))
888 spin_lock_irq (&chip->lock);
891 forte_channel_stop (&chip->rec);
892 rval = forte_channel_format (&chip->rec, ival);
896 forte_channel_stop (&chip->rec);
897 rval = forte_channel_format (&chip->play, ival);
900 spin_unlock_irq (&chip->lock);
902 return put_user (rval, (int *) arg);
904 case SNDCTL_DSP_STEREO: /* 0 - mono, 1 - stereo */
905 DPRINTK ("%s: STEREO\n", __FUNCTION__);
907 if (get_user (ival, (int *) arg))
910 spin_lock_irq (&chip->lock);
913 forte_channel_stop (&chip->rec);
914 rval = forte_channel_stereo (&chip->rec, ival);
918 forte_channel_stop (&chip->rec);
919 rval = forte_channel_stereo (&chip->play, ival);
922 spin_unlock_irq (&chip->lock);
924 return put_user (rval, (int *) arg);
926 case SNDCTL_DSP_CHANNELS: /* 1 - mono, 2 - stereo */
927 DPRINTK ("%s: CHANNELS\n", __FUNCTION__);
929 if (get_user (ival, (int *) arg))
932 spin_lock_irq (&chip->lock);
935 forte_channel_stop (&chip->rec);
936 rval = forte_channel_stereo (&chip->rec, ival-1) + 1;
940 forte_channel_stop (&chip->play);
941 rval = forte_channel_stereo (&chip->play, ival-1) + 1;
944 spin_unlock_irq (&chip->lock);
946 return put_user (rval, (int *) arg);
948 case SNDCTL_DSP_SPEED:
949 DPRINTK ("%s: SPEED\n", __FUNCTION__);
951 if (get_user (ival, (int *) arg))
954 spin_lock_irq (&chip->lock);
957 forte_channel_stop (&chip->rec);
958 rval = forte_channel_rate (&chip->rec, ival);
962 forte_channel_stop (&chip->play);
963 rval = forte_channel_rate (&chip->play, ival);
966 spin_unlock_irq (&chip->lock);
968 return put_user(rval, (int*) arg);
970 case SNDCTL_DSP_GETBLKSIZE:
971 DPRINTK ("%s: GETBLKSIZE\n", __FUNCTION__);
973 spin_lock_irq (&chip->lock);
976 ival = chip->rec.frag_sz;
979 ival = chip->play.frag_sz;
981 spin_unlock_irq (&chip->lock);
983 return put_user (ival, (int *) arg);
985 case SNDCTL_DSP_RESET:
986 DPRINTK ("%s: RESET\n", __FUNCTION__);
988 spin_lock_irq (&chip->lock);
991 forte_channel_reset (&chip->rec);
994 forte_channel_reset (&chip->play);
996 spin_unlock_irq (&chip->lock);
1000 case SNDCTL_DSP_SYNC:
1001 DPRINTK ("%s: SYNC\n", __FUNCTION__);
1004 ret = forte_channel_drain (&chip->play);
1008 case SNDCTL_DSP_POST:
1009 DPRINTK ("%s: POST\n", __FUNCTION__);
1012 spin_lock_irq (&chip->lock);
1014 if (chip->play.filled_frags)
1015 forte_channel_start (&chip->play);
1017 spin_unlock_irq (&chip->lock);
1022 case SNDCTL_DSP_SETFRAGMENT:
1023 DPRINTK ("%s: SETFRAGMENT\n", __FUNCTION__);
1025 if (get_user (ival, (int *) arg))
1028 spin_lock_irq (&chip->lock);
1031 forte_channel_buffer (&chip->rec, ival & 0xffff,
1032 (ival >> 16) & 0xffff);
1033 ival = (chip->rec.frag_num << 16) + chip->rec.frag_sz;
1037 forte_channel_buffer (&chip->play, ival & 0xffff,
1038 (ival >> 16) & 0xffff);
1039 ival = (chip->play.frag_num << 16) +chip->play.frag_sz;
1042 spin_unlock_irq (&chip->lock);
1044 return put_user (ival, (int *) arg);
1046 case SNDCTL_DSP_GETISPACE:
1047 DPRINTK ("%s: GETISPACE\n", __FUNCTION__);
1052 spin_lock_irq (&chip->lock);
1054 abi.fragstotal = chip->rec.frag_num;
1055 abi.fragsize = chip->rec.frag_sz;
1057 if (chip->rec.mapped) {
1058 abi.fragments = chip->rec.frag_num - 2;
1059 abi.bytes = abi.fragments * abi.fragsize;
1062 abi.fragments = chip->rec.filled_frags;
1063 abi.bytes = abi.fragments * abi.fragsize;
1066 spin_unlock_irq (&chip->lock);
1068 return copy_to_user ((void *) arg, &abi, sizeof (abi)) ? -EFAULT : 0;
1070 case SNDCTL_DSP_GETIPTR:
1071 DPRINTK ("%s: GETIPTR\n", __FUNCTION__);
1076 spin_lock_irq (&chip->lock);
1078 if (chip->rec.active)
1079 cinfo.ptr = chip->rec.hwptr;
1083 cinfo.bytes = chip->rec.bytes;
1084 cinfo.blocks = chip->rec.nr_irqs;
1085 chip->rec.nr_irqs = 0;
1087 spin_unlock_irq (&chip->lock);
1089 return copy_to_user ((void *) arg, &cinfo, sizeof (cinfo)) ? -EFAULT : 0;
1091 case SNDCTL_DSP_GETOSPACE:
1095 spin_lock_irq (&chip->lock);
1097 abi.fragstotal = chip->play.frag_num;
1098 abi.fragsize = chip->play.frag_sz;
1100 if (chip->play.mapped) {
1101 abi.fragments = chip->play.frag_num - 2;
1102 abi.bytes = chip->play.buf_sz;
1105 abi.fragments = chip->play.frag_num -
1106 chip->play.filled_frags;
1108 if (chip->play.residue)
1111 abi.bytes = abi.fragments * abi.fragsize +
1115 spin_unlock_irq (&chip->lock);
1117 return copy_to_user ((void *) arg, &abi, sizeof (abi)) ? -EFAULT : 0;
1119 case SNDCTL_DSP_GETOPTR:
1123 spin_lock_irq (&chip->lock);
1125 if (chip->play.active)
1126 cinfo.ptr = chip->play.hwptr;
1130 cinfo.bytes = chip->play.bytes;
1131 cinfo.blocks = chip->play.nr_irqs;
1132 chip->play.nr_irqs = 0;
1134 spin_unlock_irq (&chip->lock);
1136 return copy_to_user ((void *) arg, &cinfo, sizeof (cinfo)) ? -EFAULT : 0;
1138 case SNDCTL_DSP_GETODELAY:
1142 spin_lock_irq (&chip->lock);
1144 if (!chip->play.active) {
1147 else if (chip->play.mapped) {
1148 count = inw (chip->play.iobase + FORTE_PLY_COUNT) + 1;
1149 ival = chip->play.frag_sz - count;
1152 ival = chip->play.filled_frags * chip->play.frag_sz;
1154 if (chip->play.residue)
1155 ival += chip->play.frag_sz - chip->play.residue;
1158 spin_unlock_irq (&chip->lock);
1160 return put_user (ival, (int *) arg);
1162 case SNDCTL_DSP_SETDUPLEX:
1163 DPRINTK ("%s: SETDUPLEX\n", __FUNCTION__);
1167 case SNDCTL_DSP_GETTRIGGER:
1168 DPRINTK ("%s: GETTRIGGER\n", __FUNCTION__);
1170 return put_user (chip->trigger, (int *) arg);
1172 case SNDCTL_DSP_SETTRIGGER:
1174 if (get_user (ival, (int *) arg))
1177 DPRINTK ("%s: SETTRIGGER %d\n", __FUNCTION__, ival);
1180 spin_lock_irq (&chip->lock);
1182 if (ival & PCM_ENABLE_OUTPUT)
1183 forte_channel_start (&chip->play);
1186 forte_channel_prep (&chip->play);
1187 forte_channel_stop (&chip->play);
1190 spin_unlock_irq (&chip->lock);
1193 spin_lock_irq (&chip->lock);
1195 if (ival & PCM_ENABLE_INPUT)
1196 forte_channel_start (&chip->rec);
1199 forte_channel_prep (&chip->rec);
1200 forte_channel_stop (&chip->rec);
1203 spin_unlock_irq (&chip->lock);
1208 case SOUND_PCM_READ_RATE:
1209 DPRINTK ("%s: PCM_READ_RATE\n", __FUNCTION__);
1210 return put_user (chip->play.rate, (int *) arg);
1212 case SOUND_PCM_READ_CHANNELS:
1213 DPRINTK ("%s: PCM_READ_CHANNELS\n", __FUNCTION__);
1214 return put_user (chip->play.stereo, (int *) arg);
1216 case SOUND_PCM_READ_BITS:
1217 DPRINTK ("%s: PCM_READ_BITS\n", __FUNCTION__);
1218 return put_user (chip->play.format, (int *) arg);
1220 case SNDCTL_DSP_NONBLOCK:
1221 DPRINTK ("%s: DSP_NONBLOCK\n", __FUNCTION__);
1222 file->f_flags |= O_NONBLOCK;
1226 DPRINTK ("Unsupported ioctl: %x (%p)\n", cmd, (void *) arg);
1239 forte_dsp_open (struct inode *inode, struct file *file)
1241 struct forte_chip *chip = forte; /* FIXME: HACK FROM HELL! */
1243 if (file->f_flags & O_NONBLOCK) {
1244 if (down_trylock (&chip->open_sem)) {
1245 DPRINTK ("%s: returning -EAGAIN\n", __FUNCTION__);
1250 if (down_interruptible (&chip->open_sem)) {
1251 DPRINTK ("%s: returning -ERESTARTSYS\n", __FUNCTION__);
1252 return -ERESTARTSYS;
1256 file->private_data = forte;
1258 DPRINTK ("%s: dsp opened by %d\n", __FUNCTION__, current->pid);
1260 if (file->f_mode & FMODE_WRITE)
1261 forte_channel_init (forte, &forte->play);
1263 if (file->f_mode & FMODE_READ)
1264 forte_channel_init (forte, &forte->rec);
1271 * forte_dsp_release:
1275 forte_dsp_release (struct inode *inode, struct file *file)
1277 struct forte_chip *chip = file->private_data;
1280 DPRINTK ("%s: chip @ %p\n", __FUNCTION__, chip);
1282 if (file->f_mode & FMODE_WRITE) {
1283 forte_channel_drain (&chip->play);
1285 spin_lock_irq (&chip->lock);
1287 forte_channel_free (chip, &chip->play);
1289 spin_unlock_irq (&chip->lock);
1292 if (file->f_mode & FMODE_READ) {
1293 while (chip->rec.filled_frags > 0)
1294 interruptible_sleep_on (&chip->rec.wait);
1296 spin_lock_irq (&chip->lock);
1298 forte_channel_stop (&chip->rec);
1299 forte_channel_free (chip, &chip->rec);
1301 spin_unlock_irq (&chip->lock);
1304 up (&chip->open_sem);
1316 forte_dsp_poll (struct file *file, struct poll_table_struct *wait)
1318 struct forte_chip *chip;
1319 struct forte_channel *channel;
1320 unsigned int mask = 0;
1322 chip = file->private_data;
1324 if (file->f_mode & FMODE_WRITE) {
1325 channel = &chip->play;
1327 if (channel->active)
1328 poll_wait (file, &channel->wait, wait);
1330 spin_lock_irq (&chip->lock);
1332 if (channel->frag_num - channel->filled_frags > 0)
1333 mask |= POLLOUT | POLLWRNORM;
1335 spin_unlock_irq (&chip->lock);
1338 if (file->f_mode & FMODE_READ) {
1339 channel = &chip->rec;
1341 if (channel->active)
1342 poll_wait (file, &channel->wait, wait);
1344 spin_lock_irq (&chip->lock);
1346 if (channel->filled_frags > 0)
1347 mask |= POLLIN | POLLRDNORM;
1349 spin_unlock_irq (&chip->lock);
1361 forte_dsp_mmap (struct file *file, struct vm_area_struct *vma)
1363 struct forte_chip *chip;
1364 struct forte_channel *channel;
1368 chip = file->private_data;
1370 DPRINTK ("%s: start %lXh, size %ld, pgoff %ld\n", __FUNCTION__,
1371 vma->vm_start, vma->vm_end - vma->vm_start, vma->vm_pgoff);
1373 spin_lock_irq (&chip->lock);
1375 if (vma->vm_flags & VM_WRITE && chip->play.active) {
1380 if (vma->vm_flags & VM_READ && chip->rec.active) {
1385 if (file->f_mode & FMODE_WRITE)
1386 channel = &chip->play;
1387 else if (file->f_mode & FMODE_READ)
1388 channel = &chip->rec;
1394 forte_channel_prep (channel);
1395 channel->mapped = 1;
1397 if (vma->vm_pgoff != 0) {
1402 size = vma->vm_end - vma->vm_start;
1404 if (size > channel->buf_pages * PAGE_SIZE) {
1405 DPRINTK ("%s: size (%ld) > buf_sz (%d) \n", __FUNCTION__,
1406 size, channel->buf_sz);
1411 if (remap_page_range (vma, vma->vm_start, virt_to_phys (channel->buf),
1412 size, vma->vm_page_prot)) {
1413 DPRINTK ("%s: remap el a no worko\n", __FUNCTION__);
1421 spin_unlock_irq (&chip->lock);
1431 forte_dsp_write (struct file *file, const char *buffer, size_t bytes,
1434 struct forte_chip *chip;
1435 struct forte_channel *channel;
1436 unsigned int i = bytes, sz = 0;
1437 unsigned long flags;
1439 if (ppos != &file->f_pos)
1442 if (!access_ok (VERIFY_READ, buffer, bytes))
1445 chip = (struct forte_chip *) file->private_data;
1450 channel = &chip->play;
1455 spin_lock_irqsave (&chip->lock, flags);
1457 /* Set up buffers with the right fragment size */
1458 forte_channel_prep (channel);
1461 /* All fragment buffers in use -> wait */
1462 if (channel->frag_num - channel->filled_frags == 0) {
1463 DECLARE_WAITQUEUE (wait, current);
1465 /* For trigger or non-blocking operation, get out */
1466 if (chip->trigger || file->f_flags & O_NONBLOCK) {
1467 spin_unlock_irqrestore (&chip->lock, flags);
1471 /* Otherwise wait for buffers */
1472 add_wait_queue (&channel->wait, &wait);
1475 spin_unlock_irqrestore (&chip->lock, flags);
1477 set_current_state (TASK_INTERRUPTIBLE);
1480 spin_lock_irqsave (&chip->lock, flags);
1482 if (channel->frag_num - channel->filled_frags)
1486 remove_wait_queue (&channel->wait, &wait);
1487 set_current_state (TASK_RUNNING);
1489 if (signal_pending (current)) {
1490 spin_unlock_irqrestore (&chip->lock, flags);
1491 return -ERESTARTSYS;
1495 if (channel->residue)
1496 sz = channel->residue;
1497 else if (i > channel->frag_sz)
1498 sz = channel->frag_sz;
1502 spin_unlock_irqrestore (&chip->lock, flags);
1504 if (copy_from_user ((void *) channel->buf + channel->swptr, buffer, sz))
1507 spin_lock_irqsave (&chip->lock, flags);
1509 /* Advance software pointer */
1511 channel->swptr += sz;
1512 channel->swptr %= channel->buf_sz;
1515 /* Only bump filled_frags if a full fragment has been written */
1516 if (channel->swptr % channel->frag_sz == 0) {
1517 channel->filled_frags++;
1518 channel->residue = 0;
1521 channel->residue = channel->frag_sz - sz;
1523 /* If playback isn't active, start it */
1524 if (channel->active == 0 && chip->trigger == 0)
1525 forte_channel_start (channel);
1528 spin_unlock_irqrestore (&chip->lock, flags);
1539 forte_dsp_read (struct file *file, char *buffer, size_t bytes,
1542 struct forte_chip *chip;
1543 struct forte_channel *channel;
1544 unsigned int i = bytes, sz;
1545 unsigned long flags;
1547 if (ppos != &file->f_pos)
1550 if (!access_ok (VERIFY_WRITE, buffer, bytes))
1553 chip = (struct forte_chip *) file->private_data;
1558 channel = &chip->rec;
1563 spin_lock_irqsave (&chip->lock, flags);
1565 /* Set up buffers with the right fragment size */
1566 forte_channel_prep (channel);
1568 /* Start recording */
1570 forte_channel_start (channel);
1573 /* No fragment buffers in use -> wait */
1574 if (channel->filled_frags == 0) {
1575 DECLARE_WAITQUEUE (wait, current);
1577 /* For trigger mode operation, get out */
1578 if (chip->trigger) {
1579 spin_unlock_irqrestore (&chip->lock, flags);
1583 add_wait_queue (&channel->wait, &wait);
1586 if (channel->active == 0)
1589 if (channel->filled_frags)
1592 spin_unlock_irqrestore (&chip->lock, flags);
1594 set_current_state (TASK_INTERRUPTIBLE);
1597 spin_lock_irqsave (&chip->lock, flags);
1600 set_current_state (TASK_RUNNING);
1601 remove_wait_queue (&channel->wait, &wait);
1604 if (i > channel->frag_sz)
1605 sz = channel->frag_sz;
1609 spin_unlock_irqrestore (&chip->lock, flags);
1611 if (copy_to_user (buffer, (void *)channel->buf+channel->swptr, sz)) {
1612 DPRINTK ("%s: copy_to_user failed\n", __FUNCTION__);
1616 spin_lock_irqsave (&chip->lock, flags);
1618 /* Advance software pointer */
1620 if (channel->filled_frags > 0)
1621 channel->filled_frags--;
1622 channel->swptr += channel->frag_sz;
1623 channel->swptr %= channel->buf_sz;
1627 spin_unlock_irqrestore (&chip->lock, flags);
1633 static struct file_operations forte_dsp_fops = {
1634 .owner = THIS_MODULE,
1635 .llseek = &no_llseek,
1636 .read = &forte_dsp_read,
1637 .write = &forte_dsp_write,
1638 .poll = &forte_dsp_poll,
1639 .ioctl = &forte_dsp_ioctl,
1640 .open = &forte_dsp_open,
1641 .release = &forte_dsp_release,
1642 .mmap = &forte_dsp_mmap,
1646 /* Common ------------------------------------------------------------------ */
1654 forte_interrupt (int irq, void *dev_id, struct pt_regs *regs)
1656 struct forte_chip *chip = dev_id;
1657 struct forte_channel *channel = NULL;
1660 status = inw (chip->iobase + FORTE_IRQ_STATUS);
1662 /* If this is not for us, get outta here ASAP */
1663 if ((status & (FORTE_IRQ_PLAYBACK | FORTE_IRQ_CAPTURE)) == 0)
1666 if (status & FORTE_IRQ_PLAYBACK) {
1667 channel = &chip->play;
1669 spin_lock (&chip->lock);
1671 if (channel->frag_sz == 0)
1674 /* Declare a fragment done */
1675 if (channel->filled_frags > 0)
1676 channel->filled_frags--;
1677 channel->bytes += channel->frag_sz;
1680 /* Flip-flop between buffer I and II */
1681 channel->next_buf ^= 1;
1683 /* Advance hardware pointer by fragment size and wrap around */
1684 channel->hwptr += channel->frag_sz;
1685 channel->hwptr %= channel->buf_sz;
1687 /* Buffer I or buffer II BAR */
1688 outl (channel->buf_handle + channel->hwptr,
1689 channel->next_buf == 0 ?
1690 channel->iobase + FORTE_PLY_BUF1 :
1691 channel->iobase + FORTE_PLY_BUF2);
1693 /* If the currently playing fragment is last, schedule pause */
1694 if (channel->filled_frags == 1)
1695 forte_channel_pause (channel);
1698 /* Acknowledge interrupt */
1699 outw (FORTE_IRQ_PLAYBACK, chip->iobase + FORTE_IRQ_STATUS);
1701 if (waitqueue_active (&channel->wait))
1702 wake_up_all (&channel->wait);
1704 spin_unlock (&chip->lock);
1707 if (status & FORTE_IRQ_CAPTURE) {
1708 channel = &chip->rec;
1709 spin_lock (&chip->lock);
1711 /* One fragment filled */
1712 channel->filled_frags++;
1714 /* Get # of completed bytes */
1715 count = inw (channel->iobase + FORTE_PLY_COUNT) + 1;
1718 DPRINTK ("%s: last, filled_frags = %d\n", __FUNCTION__,
1719 channel->filled_frags);
1720 channel->filled_frags = 0;
1724 /* Buffer I or buffer II BAR */
1725 outl (channel->buf_handle + channel->hwptr,
1726 channel->next_buf == 0 ?
1727 channel->iobase + FORTE_PLY_BUF1 :
1728 channel->iobase + FORTE_PLY_BUF2);
1730 /* Flip-flop between buffer I and II */
1731 channel->next_buf ^= 1;
1733 /* Advance hardware pointer by fragment size and wrap around */
1734 channel->hwptr += channel->frag_sz;
1735 channel->hwptr %= channel->buf_sz;
1737 /* Out of buffers */
1738 if (channel->filled_frags == channel->frag_num - 1)
1739 forte_channel_stop (channel);
1741 /* Acknowledge interrupt */
1742 outw (FORTE_IRQ_CAPTURE, chip->iobase + FORTE_IRQ_STATUS);
1744 spin_unlock (&chip->lock);
1746 if (waitqueue_active (&channel->wait))
1747 wake_up_all (&channel->wait);
1759 forte_proc_read (char *page, char **start, off_t off, int count,
1760 int *eof, void *data)
1762 int i = 0, p_rate, p_chan, r_rate;
1763 unsigned short p_reg, r_reg;
1765 i += sprintf (page, "ForteMedia FM801 OSS Lite driver\n%s\n \n",
1771 p_rate = p_chan = -1;
1772 p_reg = inw (forte->iobase + FORTE_PLY_CTRL);
1773 p_rate = (p_reg >> 8) & 15;
1774 p_chan = (p_reg >> 12) & 3;
1776 if (p_rate >= 0 || p_rate <= 10)
1777 p_rate = rates[p_rate];
1779 if (p_chan >= 0 || p_chan <= 2)
1780 p_chan = channels[p_chan];
1783 r_reg = inw (forte->iobase + FORTE_CAP_CTRL);
1784 r_rate = (r_reg >> 8) & 15;
1786 if (r_rate >= 0 || r_rate <= 10)
1787 r_rate = rates[r_rate];
1789 i += sprintf (page + i,
1790 " Playback Capture\n"
1791 "FIFO empty : %-3s %-3s\n"
1792 "Buf1 Last : %-3s %-3s\n"
1793 "Buf2 Last : %-3s %-3s\n"
1794 "Started : %-3s %-3s\n"
1795 "Paused : %-3s %-3s\n"
1796 "Immed Stop : %-3s %-3s\n"
1797 "Rate : %-5d %-5d\n"
1798 "Channels : %-5d -\n"
1799 "16-bit : %-3s %-3s\n"
1800 "Stereo : %-3s %-3s\n"
1802 "Buffer Sz : %-6d %-6d\n"
1803 "Frag Sz : %-6d %-6d\n"
1804 "Frag Num : %-6d %-6d\n"
1805 "Frag msecs : %-6d %-6d\n"
1806 "Used Frags : %-6d %-6d\n"
1807 "Mapped : %-3s %-3s\n",
1808 p_reg & 1<<0 ? "yes" : "no",
1809 r_reg & 1<<0 ? "yes" : "no",
1810 p_reg & 1<<1 ? "yes" : "no",
1811 r_reg & 1<<1 ? "yes" : "no",
1812 p_reg & 1<<2 ? "yes" : "no",
1813 r_reg & 1<<2 ? "yes" : "no",
1814 p_reg & 1<<5 ? "yes" : "no",
1815 r_reg & 1<<5 ? "yes" : "no",
1816 p_reg & 1<<6 ? "yes" : "no",
1817 r_reg & 1<<6 ? "yes" : "no",
1818 p_reg & 1<<7 ? "yes" : "no",
1819 r_reg & 1<<7 ? "yes" : "no",
1822 p_reg & 1<<14 ? "yes" : "no",
1823 r_reg & 1<<14 ? "yes" : "no",
1824 p_reg & 1<<15 ? "yes" : "no",
1825 r_reg & 1<<15 ? "yes" : "no",
1826 forte->play.buf_sz, forte->rec.buf_sz,
1827 forte->play.frag_sz, forte->rec.frag_sz,
1828 forte->play.frag_num, forte->rec.frag_num,
1829 forte->play.frag_msecs, forte->rec.frag_msecs,
1830 forte->play.filled_frags, forte->rec.filled_frags,
1831 forte->play.mapped ? "yes" : "no",
1832 forte->rec.mapped ? "yes" : "no"
1842 * Creates driver info entries in /proc
1846 forte_proc_init (void)
1848 if (!proc_mkdir ("driver/forte", 0))
1851 if (!create_proc_read_entry ("driver/forte/chip", 0, 0, forte_proc_read, forte)) {
1852 remove_proc_entry ("driver/forte", NULL);
1856 if (!create_proc_read_entry("driver/forte/ac97", 0, 0, ac97_read_proc, forte->ac97)) {
1857 remove_proc_entry ("driver/forte/chip", NULL);
1858 remove_proc_entry ("driver/forte", NULL);
1867 * forte_proc_remove:
1869 * Removes driver info entries in /proc
1873 forte_proc_remove (void)
1875 remove_proc_entry ("driver/forte/ac97", NULL);
1876 remove_proc_entry ("driver/forte/chip", NULL);
1877 remove_proc_entry ("driver/forte", NULL);
1883 * @chip: Chip instance to initialize
1886 * Resets chip, configures codec and registers the driver with
1887 * the sound subsystem.
1889 * Press and hold Start for 8 secs, then switch on Run
1890 * and hold for 4 seconds. Let go of Start. Numbers
1891 * assume a properly oiled TWG.
1894 static int __devinit
1895 forte_chip_init (struct forte_chip *chip)
1899 struct ac97_codec *codec;
1901 pci_read_config_byte (chip->pci_dev, PCI_REVISION_ID, &revision);
1903 if (revision >= 0xB1) {
1904 chip->multichannel = 1;
1905 printk (KERN_INFO PFX "Multi-channel device detected.\n");
1909 outw (FORTE_CC_CODEC_RESET | FORTE_CC_AC97_RESET,
1910 chip->iobase + FORTE_CODEC_CTRL);
1912 outw (0, chip->iobase + FORTE_CODEC_CTRL);
1914 /* Request read from AC97 */
1915 outw (FORTE_AC97_READ | (0 << FORTE_AC97_ADDR_SHIFT),
1916 chip->iobase + FORTE_AC97_CMD);
1919 if ((inw (chip->iobase + FORTE_AC97_CMD) & (3<<8)) != (1<<8)) {
1920 printk (KERN_INFO PFX "AC97 codec not responding");
1925 outw (0x0808, chip->iobase + FORTE_PCM_VOL);
1926 outw (0x9f1f, chip->iobase + FORTE_FM_VOL);
1927 outw (0x8808, chip->iobase + FORTE_I2S_VOL);
1929 /* I2S control - I2S mode */
1930 outw (0x0003, chip->iobase + FORTE_I2S_MODE);
1932 /* Interrupt setup - unmask PLAYBACK & CAPTURE */
1933 cmdw = inw (chip->iobase + FORTE_IRQ_MASK);
1935 outw (cmdw, chip->iobase + FORTE_IRQ_MASK);
1937 /* Interrupt clear */
1938 outw (FORTE_IRQ_PLAYBACK|FORTE_IRQ_CAPTURE,
1939 chip->iobase + FORTE_IRQ_STATUS);
1941 /* Set up the AC97 codec */
1942 if ((codec = ac97_alloc_codec()) == NULL)
1944 codec->private_data = chip;
1945 codec->codec_read = forte_ac97_read;
1946 codec->codec_write = forte_ac97_write;
1949 if (ac97_probe_codec (codec) == 0) {
1950 printk (KERN_ERR PFX "codec probe failed\n");
1951 ac97_release_codec(codec);
1955 /* Register mixer */
1956 if ((codec->dev_mixer =
1957 register_sound_mixer (&forte_mixer_fops, -1)) < 0) {
1958 printk (KERN_ERR PFX "couldn't register mixer!\n");
1959 ac97_release_codec(codec);
1966 if ((chip->dsp = register_sound_dsp (&forte_dsp_fops, -1) ) < 0) {
1967 printk (KERN_ERR PFX "couldn't register dsp!\n");
1971 /* Register with /proc */
1972 if (forte_proc_init()) {
1973 printk (KERN_ERR PFX "couldn't add entries to /proc!\n");
1983 * @pci_dev: PCI struct for probed device
1987 * Allocates chip instance, I/O region, and IRQ
1990 forte_probe (struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
1992 struct forte_chip *chip;
1995 /* FIXME: Support more than one chip */
2000 if (pci_enable_device (pci_dev))
2003 pci_set_master (pci_dev);
2005 /* Allocate chip instance and configure */
2006 forte = (struct forte_chip *)
2007 kmalloc (sizeof (struct forte_chip), GFP_KERNEL);
2011 printk (KERN_WARNING PFX "Out of memory");
2015 memset (chip, 0, sizeof (struct forte_chip));
2016 chip->pci_dev = pci_dev;
2018 init_MUTEX(&chip->open_sem);
2019 spin_lock_init (&chip->lock);
2020 spin_lock_init (&chip->ac97_lock);
2022 if (! request_region (pci_resource_start (pci_dev, 0),
2023 pci_resource_len (pci_dev, 0), DRIVER_NAME)) {
2024 printk (KERN_WARNING PFX "Unable to reserve I/O space");
2029 chip->iobase = pci_resource_start (pci_dev, 0);
2030 chip->irq = pci_dev->irq;
2032 if (request_irq (chip->irq, forte_interrupt, SA_SHIRQ, DRIVER_NAME,
2034 printk (KERN_WARNING PFX "Unable to reserve IRQ");
2039 pci_set_drvdata (pci_dev, chip);
2041 printk (KERN_INFO PFX "FM801 chip found at 0x%04lX-0x%04lX IRQ %u\n",
2042 chip->iobase, pci_resource_end (pci_dev, 0), chip->irq);
2045 if ((ret = forte_chip_init (chip)) == 0)
2050 free_irq (chip->irq, chip);
2053 release_region (pci_resource_start (pci_dev, 0),
2054 pci_resource_len (pci_dev, 0));
2064 * @pci_dev: PCI device to unclaim
2069 forte_remove (struct pci_dev *pci_dev)
2071 struct forte_chip *chip = pci_get_drvdata (pci_dev);
2076 /* Turn volume down to avoid popping */
2077 outw (0x1f1f, chip->iobase + FORTE_PCM_VOL);
2078 outw (0x1f1f, chip->iobase + FORTE_FM_VOL);
2079 outw (0x1f1f, chip->iobase + FORTE_I2S_VOL);
2081 forte_proc_remove();
2082 free_irq (chip->irq, chip);
2083 release_region (chip->iobase, pci_resource_len (pci_dev, 0));
2085 unregister_sound_dsp (chip->dsp);
2086 unregister_sound_mixer (chip->ac97->dev_mixer);
2087 ac97_release_codec(chip->ac97);
2090 printk (KERN_INFO PFX "driver released\n");
2094 static struct pci_device_id forte_pci_ids[] = {
2095 { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
2100 static struct pci_driver forte_pci_driver = {
2101 .name = DRIVER_NAME,
2102 .id_table = forte_pci_ids,
2103 .probe = forte_probe,
2104 .remove = forte_remove,
2110 * forte_init_module:
2115 forte_init_module (void)
2117 printk (KERN_INFO PFX DRIVER_VERSION "\n");
2119 if (!pci_register_driver (&forte_pci_driver)) {
2120 pci_unregister_driver (&forte_pci_driver);
2129 * forte_cleanup_module:
2134 forte_cleanup_module (void)
2136 pci_unregister_driver (&forte_pci_driver);
2140 module_init(forte_init_module);
2141 module_exit(forte_cleanup_module);
2143 MODULE_AUTHOR("Martin K. Petersen <mkp@mkp.net>");
2144 MODULE_DESCRIPTION("ForteMedia FM801 OSS Driver");
2145 MODULE_LICENSE("GPL");
2146 MODULE_DEVICE_TABLE (pci, forte_pci_ids);