Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / sound / oss / cs4281 / cs4281m.c
index a6f09cc..0400a41 100644 (file)
@@ -111,7 +111,7 @@ static void start_adc(struct cs4281_state *s);
 // rather than 64k as some of the games work more responsively.
 // log base 2( buff sz = 32k).
 static unsigned long defaultorder = 3;
-MODULE_PARM(defaultorder, "i");
+module_param(defaultorder, ulong, 0);
 
 //
 // Turn on/off debugging compilation by commenting out "#define CSDEBUG"
@@ -159,8 +159,8 @@ MODULE_PARM(defaultorder, "i");
 #if CSDEBUG
 static unsigned long cs_debuglevel = 1;        // levels range from 1-9
 static unsigned long cs_debugmask = CS_INIT | CS_ERROR;        // use CS_DBGOUT with various mask values
-MODULE_PARM(cs_debuglevel, "i");
-MODULE_PARM(cs_debugmask, "i");
+module_param(cs_debuglevel, ulong, 0);
+module_param(cs_debugmask, ulong, 0);
 #endif
 #define CS_TRUE        1
 #define CS_FALSE       0
@@ -197,7 +197,7 @@ static const char invalid_magic[] =
 })
 
 //LIST_HEAD(cs4281_devs);
-struct list_head cs4281_devs = { &cs4281_devs, &cs4281_devs };
+static struct list_head cs4281_devs = { &cs4281_devs, &cs4281_devs };
 
 struct cs4281_state; 
 
@@ -221,7 +221,8 @@ struct cs4281_state {
 
        // hardware resources 
        unsigned int pBA0phys, pBA1phys;
-       char *pBA0, *pBA1;
+       char __iomem *pBA0;
+       char __iomem *pBA1;
        unsigned int irq;
 
        // mixer registers 
@@ -244,9 +245,9 @@ struct cs4281_state {
        void *tmpbuff;          // tmp buffer for sample conversions
        unsigned ena;
        spinlock_t lock;
-       struct semaphore open_sem;
-       struct semaphore open_sem_adc;
-       struct semaphore open_sem_dac;
+       struct mutex open_sem;
+       struct mutex open_sem_adc;
+       struct mutex open_sem_dac;
        mode_t open_mode;
        wait_queue_head_t open_wait;
        wait_queue_head_t open_wait_adc;
@@ -1018,7 +1019,7 @@ static void printpipelines(struct cs4281_state *s)
 *  Suspend - save the ac97 regs, mute the outputs and power down the part.  
 *
 ****************************************************************************/
-void cs4281_ac97_suspend(struct cs4281_state *s)
+static void cs4281_ac97_suspend(struct cs4281_state *s)
 {
        int Count,i;
 
@@ -1069,7 +1070,7 @@ void cs4281_ac97_suspend(struct cs4281_state *s)
 *  Resume - power up the part and restore its registers..  
 *
 ****************************************************************************/
-void cs4281_ac97_resume(struct cs4281_state *s)
+static void cs4281_ac97_resume(struct cs4281_state *s)
 {
        int Count,i;
 
@@ -1142,7 +1143,7 @@ HWAC97codec::SavePowerState(void)
 } // SavePowerState
 */
 
-void cs4281_SuspendFIFO(struct cs4281_state *s, struct cs4281_pipeline *pl)
+static void cs4281_SuspendFIFO(struct cs4281_state *s, struct cs4281_pipeline *pl)
 {
  /*
  * We need to save the contents of the BASIC FIFO Registers.
@@ -1150,7 +1151,7 @@ void cs4281_SuspendFIFO(struct cs4281_state *s, struct cs4281_pipeline *pl)
        pl->u32FCRn_Save = readl(s->pBA0 + pl->u32FCRnAddress);
        pl->u32FSICn_Save = readl(s->pBA0 + pl->u32FSICnAddress);
 }
-void cs4281_ResumeFIFO(struct cs4281_state *s, struct cs4281_pipeline *pl)
+static void cs4281_ResumeFIFO(struct cs4281_state *s, struct cs4281_pipeline *pl)
 {
  /*
  * We need to restore the contents of the BASIC FIFO Registers.
@@ -1158,7 +1159,7 @@ void cs4281_ResumeFIFO(struct cs4281_state *s, struct cs4281_pipeline *pl)
        writel(pl->u32FCRn_Save,s->pBA0 + pl->u32FCRnAddress);
        writel(pl->u32FSICn_Save,s->pBA0 + pl->u32FSICnAddress);
 }
-void cs4281_SuspendDMAengine(struct cs4281_state *s, struct cs4281_pipeline *pl)
+static void cs4281_SuspendDMAengine(struct cs4281_state *s, struct cs4281_pipeline *pl)
 {
        //
        // We need to save the contents of the BASIC DMA Registers.
@@ -1170,7 +1171,7 @@ void cs4281_SuspendDMAengine(struct cs4281_state *s, struct cs4281_pipeline *pl)
        pl->u32DCCn_Save = readl(s->pBA0 + pl->u32DCCnAddress);
        pl->u32DCAn_Save = readl(s->pBA0 + pl->u32DCAnAddress);
 }
-void cs4281_ResumeDMAengine(struct cs4281_state *s, struct cs4281_pipeline *pl)
+static void cs4281_ResumeDMAengine(struct cs4281_state *s, struct cs4281_pipeline *pl)
 {
        //
        // We need to save the contents of the BASIC DMA Registers.
@@ -1183,7 +1184,7 @@ void cs4281_ResumeDMAengine(struct cs4281_state *s, struct cs4281_pipeline *pl)
        writel( pl->u32DCAn_Save, s->pBA0 + pl->u32DCAnAddress);
 }
 
-int cs4281_suspend(struct cs4281_state *s)
+static int cs4281_suspend(struct cs4281_state *s)
 {
        int i;
        u32 u32CLKCR1;
@@ -1339,7 +1340,7 @@ int cs4281_suspend(struct cs4281_state *s)
        return 0;
 }
 
-int cs4281_resume(struct cs4281_state *s)
+static int cs4281_resume(struct cs4281_state *s)
 {
        int i;
        unsigned temp1;
@@ -1694,7 +1695,7 @@ static void start_adc(struct cs4281_state *s)
 #define DMABUF_MINORDER 1      // ==> min buffer size = 8K.
 
 
-void dealloc_dmabuf(struct cs4281_state *s, struct dmabuf *db)
+static void dealloc_dmabuf(struct cs4281_state *s, struct dmabuf *db)
 {
        struct page *map, *mapend;
 
@@ -1755,7 +1756,7 @@ static int prog_dmabuf(struct cs4281_state *s, struct dmabuf *db)
                }
                db->buforder = order;
                // Now mark the pages as reserved; otherwise the 
-               // remap_page_range() in cs4281_mmap doesn't work.
+               // remap_pfn_range() in cs4281_mmap doesn't work.
                // 1. get index to last page in mem_map array for rawbuf.
                mapend = virt_to_page(db->rawbuf + 
                        (PAGE_SIZE << db->buforder) - 1);
@@ -1778,7 +1779,7 @@ static int prog_dmabuf(struct cs4281_state *s, struct dmabuf *db)
                }
                s->buforder_tmpbuff = order;
                // Now mark the pages as reserved; otherwise the 
-               // remap_page_range() in cs4281_mmap doesn't work.
+               // remap_pfn_range() in cs4281_mmap doesn't work.
                // 1. get index to last page in mem_map array for rawbuf.
                mapend = virt_to_page(s->tmpbuff + 
                                (PAGE_SIZE << s->buforder_tmpbuff) - 1);
@@ -3135,9 +3136,10 @@ static int cs4281_mmap(struct file *file, struct vm_area_struct *vma)
        size = vma->vm_end - vma->vm_start;
        if (size > (PAGE_SIZE << db->buforder))
                return -EINVAL;
-       if (remap_page_range
-           (vma, vma->vm_start, virt_to_phys(db->rawbuf), size,
-            vma->vm_page_prot)) return -EAGAIN;
+       if (remap_pfn_range(vma, vma->vm_start,
+                               virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
+                               size, vma->vm_page_prot))
+               return -EAGAIN;
        db->mapped = 1;
 
        CS_DBGOUT(CS_FUNCTION | CS_PARMS | CS_OPEN, 4,
@@ -3596,20 +3598,20 @@ static int cs4281_release(struct inode *inode, struct file *file)
 
        if (file->f_mode & FMODE_WRITE) {
                drain_dac(s, file->f_flags & O_NONBLOCK);
-               down(&s->open_sem_dac);
+               mutex_lock(&s->open_sem_dac);
                stop_dac(s);
                dealloc_dmabuf(s, &s->dma_dac);
                s->open_mode &= ~FMODE_WRITE;
-               up(&s->open_sem_dac);
+               mutex_unlock(&s->open_sem_dac);
                wake_up(&s->open_wait_dac);
        }
        if (file->f_mode & FMODE_READ) {
                drain_adc(s, file->f_flags & O_NONBLOCK);
-               down(&s->open_sem_adc);
+               mutex_lock(&s->open_sem_adc);
                stop_adc(s);
                dealloc_dmabuf(s, &s->dma_adc);
                s->open_mode &= ~FMODE_READ;
-               up(&s->open_sem_adc);
+               mutex_unlock(&s->open_sem_adc);
                wake_up(&s->open_wait_adc);
        }
        return 0;
@@ -3649,33 +3651,33 @@ static int cs4281_open(struct inode *inode, struct file *file)
                return -ENODEV;
        }
        if (file->f_mode & FMODE_WRITE) {
-               down(&s->open_sem_dac);
+               mutex_lock(&s->open_sem_dac);
                while (s->open_mode & FMODE_WRITE) {
                        if (file->f_flags & O_NONBLOCK) {
-                               up(&s->open_sem_dac);
+                               mutex_unlock(&s->open_sem_dac);
                                return -EBUSY;
                        }
-                       up(&s->open_sem_dac);
+                       mutex_unlock(&s->open_sem_dac);
                        interruptible_sleep_on(&s->open_wait_dac);
 
                        if (signal_pending(current))
                                return -ERESTARTSYS;
-                       down(&s->open_sem_dac);
+                       mutex_lock(&s->open_sem_dac);
                }
        }
        if (file->f_mode & FMODE_READ) {
-               down(&s->open_sem_adc);
+               mutex_lock(&s->open_sem_adc);
                while (s->open_mode & FMODE_READ) {
                        if (file->f_flags & O_NONBLOCK) {
-                               up(&s->open_sem_adc);
+                               mutex_unlock(&s->open_sem_adc);
                                return -EBUSY;
                        }
-                       up(&s->open_sem_adc);
+                       mutex_unlock(&s->open_sem_adc);
                        interruptible_sleep_on(&s->open_wait_adc);
 
                        if (signal_pending(current))
                                return -ERESTARTSYS;
-                       down(&s->open_sem_adc);
+                       mutex_lock(&s->open_sem_adc);
                }
        }
        s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
@@ -3689,7 +3691,7 @@ static int cs4281_open(struct inode *inode, struct file *file)
                s->ena &= ~FMODE_READ;
                s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
                    s->dma_adc.subdivision = 0;
-               up(&s->open_sem_adc);
+               mutex_unlock(&s->open_sem_adc);
 
                if (prog_dmabuf_adc(s)) {
                        CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
@@ -3709,7 +3711,7 @@ static int cs4281_open(struct inode *inode, struct file *file)
                s->ena &= ~FMODE_WRITE;
                s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
                    s->dma_dac.subdivision = 0;
-               up(&s->open_sem_dac);
+               mutex_unlock(&s->open_sem_dac);
 
                if (prog_dmabuf_dac(s)) {
                        CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
@@ -3976,17 +3978,17 @@ static int cs4281_midi_open(struct inode *inode, struct file *file)
        VALIDATE_STATE(s);
        file->private_data = s;
        // wait for device to become free 
-       down(&s->open_sem);
+       mutex_lock(&s->open_sem);
        while (s->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
                if (file->f_flags & O_NONBLOCK) {
-                       up(&s->open_sem);
+                       mutex_unlock(&s->open_sem);
                        return -EBUSY;
                }
-               up(&s->open_sem);
+               mutex_unlock(&s->open_sem);
                interruptible_sleep_on(&s->open_wait);
                if (signal_pending(current))
                        return -ERESTARTSYS;
-               down(&s->open_sem);
+               mutex_lock(&s->open_sem);
        }
        spin_lock_irqsave(&s->lock, flags);
        if (!(s->open_mode & (FMODE_MIDI_READ | FMODE_MIDI_WRITE))) {
@@ -4016,7 +4018,7 @@ static int cs4281_midi_open(struct inode *inode, struct file *file)
            (file->
             f_mode << FMODE_MIDI_SHIFT) & (FMODE_MIDI_READ |
                                            FMODE_MIDI_WRITE);
-       up(&s->open_sem);
+       mutex_unlock(&s->open_sem);
        return nonseekable_open(inode, file);
 }
 
@@ -4055,7 +4057,7 @@ static int cs4281_midi_release(struct inode *inode, struct file *file)
                remove_wait_queue(&s->midi.owait, &wait);
                current->state = TASK_RUNNING;
        }
-       down(&s->open_sem);
+       mutex_lock(&s->open_sem);
        s->open_mode &=
            (~(file->f_mode << FMODE_MIDI_SHIFT)) & (FMODE_MIDI_READ |
                                                     FMODE_MIDI_WRITE);
@@ -4065,7 +4067,7 @@ static int cs4281_midi_release(struct inode *inode, struct file *file)
                del_timer(&s->midi.timer);
        }
        spin_unlock_irqrestore(&s->lock, flags);
-       up(&s->open_sem);
+       mutex_unlock(&s->open_sem);
        wake_up(&s->open_wait);
        return 0;
 }
@@ -4094,7 +4096,7 @@ static /*const */ struct file_operations cs4281_midi_fops = {
 static struct initvol {
        int mixch;
        int vol;
-} initvol[] __initdata = {
+} initvol[] __devinitdata = {
 
        {
        SOUND_MIXER_WRITE_VOLUME, 0x4040}, {
@@ -4110,7 +4112,7 @@ static struct initvol {
 
 
 #ifndef NOT_CS4281_PM
-void __devinit cs4281_BuildFIFO(
+static void __devinit cs4281_BuildFIFO(
        struct cs4281_pipeline *p, 
        struct cs4281_state *s)
 {
@@ -4157,7 +4159,7 @@ void __devinit cs4281_BuildFIFO(
 
 }
 
-void __devinit cs4281_BuildDMAengine(
+static void __devinit cs4281_BuildDMAengine(
        struct cs4281_pipeline *p, 
        struct cs4281_state *s)
 {
@@ -4227,7 +4229,7 @@ void __devinit cs4281_BuildDMAengine(
 
 }
 
-void __devinit cs4281_InitPM(struct cs4281_state *s)
+static void __devinit cs4281_InitPM(struct cs4281_state *s)
 {
        int i;
        struct cs4281_pipeline *p;
@@ -4253,9 +4255,6 @@ void __devinit cs4281_InitPM(struct cs4281_state *s)
 static int __devinit cs4281_probe(struct pci_dev *pcidev,
                                  const struct pci_device_id *pciid)
 {
-#ifndef NOT_CS4281_PM
-       struct pm_dev *pmdev;
-#endif
        struct cs4281_state *s;
        dma_addr_t dma_mask;
        mm_segment_t fs;
@@ -4301,9 +4300,9 @@ static int __devinit cs4281_probe(struct pci_dev *pcidev,
        init_waitqueue_head(&s->open_wait_dac);
        init_waitqueue_head(&s->midi.iwait);
        init_waitqueue_head(&s->midi.owait);
-       init_MUTEX(&s->open_sem);
-       init_MUTEX(&s->open_sem_adc);
-       init_MUTEX(&s->open_sem_dac);
+       mutex_init(&s->open_sem);
+       mutex_init(&s->open_sem_adc);
+       mutex_init(&s->open_sem_dac);
        spin_lock_init(&s->lock);
        s->pBA0phys = pci_resource_start(pcidev, 0);
        s->pBA1phys = pci_resource_start(pcidev, 1);
@@ -4347,7 +4346,7 @@ static int __devinit cs4281_probe(struct pci_dev *pcidev,
        s->pcidev = pcidev;
        s->irq = pcidev->irq;
        if (request_irq
-           (s->irq, cs4281_interrupt, SA_SHIRQ, "Crystal CS4281", s)) {
+           (s->irq, cs4281_interrupt, IRQF_SHARED, "Crystal CS4281", s)) {
                CS_DBGOUT(CS_INIT | CS_ERROR, 1,
                          printk(KERN_ERR "cs4281: irq %u in use\n", s->irq));
                goto err_irq;
@@ -4371,19 +4370,7 @@ static int __devinit cs4281_probe(struct pci_dev *pcidev,
        }
 #ifndef NOT_CS4281_PM
        cs4281_InitPM(s);
-       pmdev = cs_pm_register(PM_PCI_DEV, PM_PCI_ID(pcidev), cs4281_pm_callback);
-       if (pmdev)
-       {
-               CS_DBGOUT(CS_INIT | CS_PM, 4, printk(KERN_INFO
-                        "cs4281: probe() pm_register() succeeded (%p).\n", pmdev));
-               pmdev->data = s;
-       }
-       else
-       {
-               CS_DBGOUT(CS_INIT | CS_PM | CS_ERROR, 0, printk(KERN_INFO
-                        "cs4281: probe() pm_register() failed (%p).\n", pmdev));
-               s->pm.flags |= CS4281_PM_NOT_REGISTERED;
-       }
+       s->pm.flags |= CS4281_PM_NOT_REGISTERED;
 #endif
 
        pci_set_master(pcidev); // enable bus mastering 
@@ -4457,7 +4444,7 @@ static struct pci_device_id cs4281_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, cs4281_pci_tbl);
 
-struct pci_driver cs4281_pci_driver = {
+static struct pci_driver cs4281_pci_driver = {
        .name     = "cs4281",
        .id_table = cs4281_pci_tbl,
        .probe    = cs4281_probe,
@@ -4466,7 +4453,7 @@ struct pci_driver cs4281_pci_driver = {
        .resume   = CS4281_RESUME_TBL,
 };
 
-int __init cs4281_init_module(void)
+static int __init cs4281_init_module(void)
 {
        int rtn = 0;
        CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO 
@@ -4474,19 +4461,16 @@ int __init cs4281_init_module(void)
        printk(KERN_INFO "cs4281: version v%d.%02d.%d time " __TIME__ " "
               __DATE__ "\n", CS4281_MAJOR_VERSION, CS4281_MINOR_VERSION,
               CS4281_ARCH);
-       rtn = pci_module_init(&cs4281_pci_driver);
+       rtn = pci_register_driver(&cs4281_pci_driver);
 
        CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
                  printk(KERN_INFO "cs4281: cs4281_init_module()- (%d)\n",rtn));
        return rtn;
 }
 
-void __exit cs4281_cleanup_module(void)
+static void __exit cs4281_cleanup_module(void)
 {
        pci_unregister_driver(&cs4281_pci_driver);
-#ifndef NOT_CS4281_PM
-       cs_pm_unregister_all(cs4281_pm_callback);
-#endif
        CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
                  printk(KERN_INFO "cs4281: cleanup_cs4281() finished\n"));
 }
@@ -4501,9 +4485,3 @@ MODULE_LICENSE("GPL");
 module_init(cs4281_init_module);
 module_exit(cs4281_cleanup_module);
 
-#ifndef MODULE
-int __init init_cs4281(void)
-{
-       return cs4281_init_module();
-}
-#endif