vserver 1.9.5.x5
[linux-2.6.git] / sound / oss / ad1848.c
index 0195b64..4384dac 100644 (file)
@@ -123,9 +123,9 @@ ad1848_port_info;
 static struct address_info cfg;
 static int nr_ad1848_devs;
 
-int deskpro_xl;
-int deskpro_m;
-int soundpro;
+static int deskpro_xl;
+static int deskpro_m;
+static int soundpro;
 
 static volatile signed char irq2dev[17] = {
        -1, -1, -1, -1, -1, -1, -1, -1,
@@ -624,6 +624,7 @@ static void ad1848_mixer_reset(ad1848_info * devc)
                        devc->supported_devices = MODE3_MIXER_DEVICES;
                        break;
                case MD_4232:
+               case MD_4235:
                case MD_4236:
                        devc->supported_devices = MODE3_MIXER_DEVICES;
                        break;
@@ -672,14 +673,14 @@ static void ad1848_mixer_reset(ad1848_info * devc)
        spin_unlock_irqrestore(&devc->lock,flags);
 }
 
-static int ad1848_mixer_ioctl(int dev, unsigned int cmd, caddr_t arg)
+static int ad1848_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
 {
        ad1848_info *devc = mixer_devs[dev]->devc;
        int val;
 
        if (cmd == SOUND_MIXER_PRIVATE1) 
        {
-               if (get_user(val, (int *)arg))
+               if (get_user(val, (int __user *)arg))
                        return -EFAULT;
 
                if (val != 0xffff) 
@@ -697,11 +698,11 @@ static int ad1848_mixer_ioctl(int dev, unsigned int cmd, caddr_t arg)
                        spin_unlock_irqrestore(&devc->lock,flags);
                }
                val = devc->mixer_output_port;
-               return put_user(val, (int *)arg);
+               return put_user(val, (int __user *)arg);
        }
        if (cmd == SOUND_MIXER_PRIVATE2)
        {
-               if (get_user(val, (int *)arg))
+               if (get_user(val, (int __user *)arg))
                        return -EFAULT;
                return(ad1848_control(AD1848_MIXER_REROUTE, val));
        }
@@ -712,18 +713,18 @@ static int ad1848_mixer_ioctl(int dev, unsigned int cmd, caddr_t arg)
                        switch (cmd & 0xff) 
                        {
                                case SOUND_MIXER_RECSRC:
-                                       if (get_user(val, (int *)arg))
+                                       if (get_user(val, (int __user *)arg))
                                                return -EFAULT;
                                        val = ad1848_set_recmask(devc, val);
                                        break;
                                
                                default:
-                                       if (get_user(val, (int *)arg))
+                                       if (get_user(val, (int __user *)arg))
                                        return -EFAULT;
                                        val = ad1848_mixer_set(devc, cmd & 0xff, val);
                                        break;
                        } 
-                       return put_user(val, (int *)arg);
+                       return put_user(val, (int __user *)arg);
                }
                else
                {
@@ -759,7 +760,7 @@ static int ad1848_mixer_ioctl(int dev, unsigned int cmd, caddr_t arg)
                                        val = ad1848_mixer_get(devc, cmd & 0xff);
                                        break;
                        }
-                       return put_user(val, (int *)arg);
+                       return put_user(val, (int __user *)arg);
                }
        }
        else
@@ -1537,7 +1538,7 @@ static void ad1848_init_hw(ad1848_info * devc)
        ad1848_mixer_reset(devc);
 }
 
-int ad1848_detect(int io_base, int *ad_flags, int *osp)
+int ad1848_detect(struct resource *ports, int *ad_flags, int *osp)
 {
        unsigned char tmp;
        ad1848_info *devc = &adev_info[nr_ad1848_devs];
@@ -1547,6 +1548,7 @@ int ad1848_detect(int io_base, int *ad_flags, int *osp)
        int ad1847_flag = 0;
        int cs4248_flag = 0;
        int sscape_flag = 0;
+       int io_base = ports->start;
 
        int i;
 
@@ -1577,11 +1579,6 @@ int ad1848_detect(int io_base, int *ad_flags, int *osp)
                printk(KERN_ERR "ad1848 - Too many audio devices\n");
                return 0;
        }
-       if (check_region(io_base, 4))
-       {
-               printk(KERN_ERR "ad1848.c: Port %x not free.\n", io_base);
-               return 0;
-       }
        spin_lock_init(&devc->lock);
        devc->base = io_base;
        devc->irq_ok = 0;
@@ -1950,7 +1947,7 @@ int ad1848_detect(int io_base, int *ad_flags, int *osp)
        return 1;
 }
 
-int ad1848_init (char *name, int io_base, int irq, int dma_playback,
+int ad1848_init (char *name, struct resource *ports, int irq, int dma_playback,
                int dma_capture, int share_dma, int *osp, struct module *owner)
 {
        /*
@@ -1985,8 +1982,7 @@ int ad1848_init (char *name, int io_base, int irq, int dma_playback,
                sprintf(dev_name,
                        "Generic audio codec (%s)", devc->chip_name);
 
-       if (!request_region(devc->base, 4, devc->name))
-               return -1;
+       rename_region(ports, devc->name);
 
        conf_printf2(dev_name, devc->base, devc->irq, dma_playback, dma_capture);
 
@@ -2521,21 +2517,16 @@ static int init_deskpro(struct address_info *hw_config)
        return 1;
 }
 
-int probe_ms_sound(struct address_info *hw_config)
+int probe_ms_sound(struct address_info *hw_config, struct resource *ports)
 {
        unsigned char   tmp;
 
        DDB(printk("Entered probe_ms_sound(%x, %d)\n", hw_config->io_base, hw_config->card_subtype));
 
-       if (check_region(hw_config->io_base, 8))
-       {
-               printk(KERN_ERR "MSS: I/O port conflict\n");
-               return 0;
-       }
        if (hw_config->card_subtype == 1)       /* Has no IRQ/DMA registers */
        {
                /* check_opl3(0x388, hw_config); */
-               return ad1848_detect(hw_config->io_base + 4, NULL, hw_config->osp);
+               return ad1848_detect(ports, NULL, hw_config->osp);
        }
 
        if (deskpro_xl && hw_config->card_subtype == 2) /* Compaq Deskpro XL */
@@ -2561,7 +2552,7 @@ int probe_ms_sound(struct address_info *hw_config)
                  int             ret;
 
                  DDB(printk("I/O address is inactive (%x)\n", tmp));
-                 if (!(ret = ad1848_detect(hw_config->io_base + 4, NULL, hw_config->osp)))
+                 if (!(ret = ad1848_detect(ports, NULL, hw_config->osp)))
                          return 0;
                  return 1;
        }
@@ -2574,7 +2565,7 @@ int probe_ms_sound(struct address_info *hw_config)
 
                MDB(printk(KERN_ERR "No MSS signature detected on port 0x%x (0x%x)\n", hw_config->io_base, (int) inb(hw_config->io_base + 3)));
                DDB(printk("Trying to detect codec anyway but IRQ/DMA may not work\n"));
-               if (!(ret = ad1848_detect(hw_config->io_base + 4, NULL, hw_config->osp)))
+               if (!(ret = ad1848_detect(ports, NULL, hw_config->osp)))
                        return 0;
 
                hw_config->card_subtype = 1;
@@ -2609,10 +2600,10 @@ int probe_ms_sound(struct address_info *hw_config)
                printk(KERN_ERR "MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config->irq);
                return 0;
        }
-       return ad1848_detect(hw_config->io_base + 4, NULL, hw_config->osp);
+       return ad1848_detect(ports, NULL, hw_config->osp);
 }
 
-void attach_ms_sound(struct address_info *hw_config, struct module *owner)
+void attach_ms_sound(struct address_info *hw_config, struct resource *ports, struct module *owner)
 {
        static signed char interrupt_bits[12] =
        {
@@ -2633,13 +2624,12 @@ void attach_ms_sound(struct address_info *hw_config, struct module *owner)
 
        if (hw_config->card_subtype == 1)       /* Has no IRQ/DMA registers */
        {
-               hw_config->slots[0] = ad1848_init("MS Sound System", hw_config->io_base + 4,
+               hw_config->slots[0] = ad1848_init("MS Sound System", ports,
                                                    hw_config->irq,
                                                    hw_config->dma,
                                                    hw_config->dma2, 0, 
                                                    hw_config->osp,
                                                    owner);
-               request_region(hw_config->io_base, 4, "WSS config");
                return;
        }
        /*
@@ -2650,6 +2640,8 @@ void attach_ms_sound(struct address_info *hw_config, struct module *owner)
        if (bits == -1)
        {
                printk(KERN_ERR "MSS: Bad IRQ %d\n", hw_config->irq);
+               release_region(ports->start, 4);
+               release_region(ports->start - 4, 4);
                return;
        }
        outb((bits | 0x40), config_port);
@@ -2693,12 +2685,11 @@ void attach_ms_sound(struct address_info *hw_config, struct module *owner)
 
        outb((bits | dma_bits[dma] | dma2_bit), config_port);   /* Write IRQ+DMA setup */
 
-       hw_config->slots[0] = ad1848_init("MS Sound System", hw_config->io_base + 4,
+       hw_config->slots[0] = ad1848_init("MS Sound System", ports,
                                          hw_config->irq,
                                          dma, dma2, 0,
                                          hw_config->osp,
                                          THIS_MODULE);
-       request_region(hw_config->io_base, 4, "WSS config");
 }
 
 void unload_ms_sound(struct address_info *hw_config)
@@ -2914,24 +2905,24 @@ static int __initdata dma = -1;
 static int __initdata dma2 = -1;
 static int __initdata type = 0;
 
-MODULE_PARM(io, "i");                   /* I/O for a raw AD1848 card */
-MODULE_PARM(irq, "i");                  /* IRQ to use */
-MODULE_PARM(dma, "i");                  /* First DMA channel */
-MODULE_PARM(dma2, "i");                 /* Second DMA channel */
-MODULE_PARM(type, "i");                 /* Card type */
-MODULE_PARM(deskpro_xl, "i");           /* Special magic for Deskpro XL boxen */
-MODULE_PARM(deskpro_m, "i");            /* Special magic for Deskpro M box */
-MODULE_PARM(soundpro, "i");             /* More special magic for SoundPro chips */
+module_param(io, int, 0);              /* I/O for a raw AD1848 card */
+module_param(irq, int, 0);             /* IRQ to use */
+module_param(dma, int, 0);             /* First DMA channel */
+module_param(dma2, int, 0);            /* Second DMA channel */
+module_param(type, int, 0);            /* Card type */
+module_param(deskpro_xl, bool, 0);     /* Special magic for Deskpro XL boxen */
+module_param(deskpro_m, bool, 0);      /* Special magic for Deskpro M box */
+module_param(soundpro, bool, 0);       /* More special magic for SoundPro chips */
 
 #ifdef CONFIG_PNP
-MODULE_PARM(isapnp,    "i");
-MODULE_PARM(isapnpjump,        "i");
-MODULE_PARM(reverse,   "i");
+module_param(isapnp, int, 0);
+module_param(isapnpjump, int, 0);
+module_param(reverse, bool, 0);
 MODULE_PARM_DESC(isapnp,       "When set to 0, Plug & Play support will be disabled");
 MODULE_PARM_DESC(isapnpjump,   "Jumps to a specific slot in the driver's PnP table. Use the source, Luke.");
 MODULE_PARM_DESC(reverse,      "When set to 1, will reverse ISAPnP search order");
 
-struct pnp_dev *ad1848_dev  = NULL;
+static struct pnp_dev  *ad1848_dev  = NULL;
 
 /* Please add new entries at the end of the table */
 static struct {
@@ -2961,7 +2952,7 @@ static struct {
                ISAPNP_VENDOR('G','R','V'), ISAPNP_DEVICE(0x0001),
                ISAPNP_VENDOR('G','R','V'), ISAPNP_FUNCTION(0x0000),
                0, 0, 0, 1, 0},
-       {0}
+       {NULL}
 };
 
 static struct isapnp_device_id id_table[] __devinitdata = {
@@ -3094,6 +3085,7 @@ static int __init init_ad1848(void)
 #endif
 
        if(io != -1) {
+               struct resource *ports;
                if( isapnp == 0 )
                {
                        if(irq == -1 || dma == -1) {
@@ -3108,9 +3100,22 @@ static int __init init_ad1848(void)
                        cfg.card_subtype = type;
                }
 
-               if(!probe_ms_sound(&cfg))
+               ports = request_region(io + 4, 4, "ad1848");
+
+               if (!ports)
+                       return -EBUSY;
+
+               if (!request_region(io, 4, "WSS config")) {
+                       release_region(io + 4, 4);
+                       return -EBUSY;
+               }
+
+               if (!probe_ms_sound(&cfg, ports)) {
+                       release_region(io + 4, 4);
+                       release_region(io, 4);
                        return -ENODEV;
-               attach_ms_sound(&cfg, THIS_MODULE);
+               }
+               attach_ms_sound(&cfg, ports, THIS_MODULE);
                loaded = 1;
        }
        return 0;