fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / sound / isa / opl3sa2.c
index 9d84319..419b4eb 100644 (file)
@@ -33,6 +33,7 @@
 #include <sound/mpu401.h>
 #include <sound/opl3.h>
 #include <sound/initval.h>
+#include <sound/tlv.h>
 
 #include <asm/io.h>
 
@@ -59,7 +60,7 @@ static long midi_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* 0x330,0x300 */
 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;       /* 0,1,3,5,9,11,12,15 */
 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;      /* 1,3,5,6,7 */
 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;      /* 1,3,5,6,7 */
-static int opl3sa3_ymode[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0 };   /* 0,1,2,3 */ /*SL Added*/
+static int opl3sa3_ymode[SNDRV_CARDS];   /* 0,1,2,3 */ /*SL Added*/
 
 module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for OPL3-SA soundcard.");
@@ -95,6 +96,7 @@ static struct platform_device *platform_devices[SNDRV_CARDS];
 static int pnp_registered;
 static int pnpc_registered;
 #endif
+static unsigned int snd_opl3sa2_devices;
 
 /* control ports */
 #define OPL3SA2_PM_CTRL                0x01
@@ -220,7 +222,7 @@ static void snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsig
        spin_unlock_irqrestore(&chip->reg_lock, flags);
 }
 
-static int __init snd_opl3sa2_detect(struct snd_opl3sa2 *chip)
+static int __devinit snd_opl3sa2_detect(struct snd_opl3sa2 *chip)
 {
        struct snd_card *card;
        unsigned long port;
@@ -292,7 +294,7 @@ static int __init snd_opl3sa2_detect(struct snd_opl3sa2 *chip)
        return 0;
 }
 
-static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id)
 {
        unsigned short status;
        struct snd_opl3sa2 *chip = dev_id;
@@ -310,12 +312,12 @@ static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id, struct pt_regs *
 
        if ((status & 0x10) && chip->rmidi != NULL) {
                handled = 1;
-               snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
+               snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
        }
 
        if (status & 0x07) {    /* TI,CI,PI */
                handled = 1;
-               snd_cs4231_interrupt(irq, chip->cs4231, regs);
+               snd_cs4231_interrupt(irq, chip->cs4231);
        }
 
        if (status & 0x40) { /* hardware volume change */
@@ -336,6 +338,14 @@ static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id, struct pt_regs *
   .info = snd_opl3sa2_info_single, \
   .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \
   .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
+#define OPL3SA2_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
+  .name = xname, .index = xindex, \
+  .info = snd_opl3sa2_info_single, \
+  .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \
+  .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \
+  .tlv = { .p = (xtlv) } }
 
 static int snd_opl3sa2_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
@@ -394,6 +404,14 @@ static int snd_opl3sa2_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_
   .info = snd_opl3sa2_info_double, \
   .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \
   .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
+#define OPL3SA2_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert, xtlv) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
+  .name = xname, .index = xindex, \
+  .info = snd_opl3sa2_info_double, \
+  .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \
+  .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22), \
+  .tlv = { .p = (xtlv) } }
 
 static int snd_opl3sa2_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
@@ -468,11 +486,16 @@ static int snd_opl3sa2_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_
        return change;
 }
 
+static DECLARE_TLV_DB_SCALE(db_scale_master, -3000, 200, 0);
+static DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
+
 static struct snd_kcontrol_new snd_opl3sa2_controls[] = {
 OPL3SA2_DOUBLE("Master Playback Switch", 0, 0x07, 0x08, 7, 7, 1, 1),
-OPL3SA2_DOUBLE("Master Playback Volume", 0, 0x07, 0x08, 0, 0, 15, 1),
+OPL3SA2_DOUBLE_TLV("Master Playback Volume", 0, 0x07, 0x08, 0, 0, 15, 1,
+                  db_scale_master),
 OPL3SA2_SINGLE("Mic Playback Switch", 0, 0x09, 7, 1, 1),
-OPL3SA2_SINGLE("Mic Playback Volume", 0, 0x09, 0, 31, 1)
+OPL3SA2_SINGLE_TLV("Mic Playback Volume", 0, 0x09, 0, 31, 1,
+                  db_scale_5bit_12db_max),
 };
 
 static struct snd_kcontrol_new snd_opl3sa2_tone_controls[] = {
@@ -488,7 +511,7 @@ static void snd_opl3sa2_master_free(struct snd_kcontrol *kcontrol)
        chip->master_volume = NULL;
 }
 
-static int __init snd_opl3sa2_mixer(struct snd_opl3sa2 *chip)
+static int __devinit snd_opl3sa2_mixer(struct snd_opl3sa2 *chip)
 {
        struct snd_card *card = chip->card;
        struct snd_ctl_elem_id id1, id2;
@@ -582,8 +605,8 @@ static int snd_opl3sa2_resume(struct snd_card *card)
 #endif /* CONFIG_PM */
 
 #ifdef CONFIG_PNP
-static int __init snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip,
-                                 struct pnp_dev *pdev)
+static int __devinit snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip,
+                                    struct pnp_dev *pdev)
 {
        struct pnp_resource_table * cfg;
        int err;
@@ -682,7 +705,7 @@ static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev)
                chip->single_dma = 1;
        if ((err = snd_opl3sa2_detect(chip)) < 0)
                return err;
-       if (request_irq(xirq, snd_opl3sa2_interrupt, SA_INTERRUPT, "OPL3-SA2", chip)) {
+       if (request_irq(xirq, snd_opl3sa2_interrupt, IRQF_DISABLED, "OPL3-SA2", chip)) {
                snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq);
                return -ENODEV;
        }
@@ -760,6 +783,7 @@ static int __devinit snd_opl3sa2_pnp_detect(struct pnp_dev *pdev,
        }
        pnp_set_drvdata(pdev, card);
        dev++;
+       snd_opl3sa2_devices++;
        return 0;
 }
 
@@ -826,6 +850,7 @@ static int __devinit snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard,
        }
        pnp_set_card_drvdata(pcard, card);
        dev++;
+       snd_opl3sa2_devices++;
        return 0;
 }
 
@@ -859,7 +884,7 @@ static struct pnp_card_driver opl3sa2_pnpc_driver = {
 };
 #endif /* CONFIG_PNP */
 
-static int __init snd_opl3sa2_nonpnp_probe(struct platform_device *pdev)
+static int __devinit snd_opl3sa2_nonpnp_probe(struct platform_device *pdev)
 {
        struct snd_card *card;
        int err;
@@ -944,52 +969,48 @@ static void __init_or_module snd_opl3sa2_unregister_all(void)
 
 static int __init alsa_card_opl3sa2_init(void)
 {
-       int i, err, cards = 0;
+       int i, err;
 
        if ((err = platform_driver_register(&snd_opl3sa2_nonpnp_driver)) < 0)
                return err;
 
-       for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
+       for (i = 0; i < SNDRV_CARDS; i++) {
                struct platform_device *device;
+               if (! enable[i])
+                       continue;
 #ifdef CONFIG_PNP
                if (isapnp[i])
                        continue;
 #endif
                device = platform_device_register_simple(OPL3SA2_DRIVER,
                                                         i, NULL, 0);
-               if (IS_ERR(device)) {
-                       err = PTR_ERR(device);
-                       goto errout;
+               if (IS_ERR(device))
+                       continue;
+               if (!platform_get_drvdata(device)) {
+                       platform_device_unregister(device);
+                       continue;
                }
                platform_devices[i] = device;
-               cards++;
+               snd_opl3sa2_devices++;
        }
 
 #ifdef CONFIG_PNP
        err = pnp_register_driver(&opl3sa2_pnp_driver);
-       if (err >= 0) {
+       if (!err)
                pnp_registered = 1;
-               cards += err;
-       }
        err = pnp_register_card_driver(&opl3sa2_pnpc_driver);
-       if (err >= 0) {
+       if (!err)
                pnpc_registered = 1;
-               cards += err;
-       }
 #endif
 
-       if (!cards) {
+       if (!snd_opl3sa2_devices) {
 #ifdef MODULE
                snd_printk(KERN_ERR "Yamaha OPL3-SA soundcard not found or device busy\n");
 #endif
-               err = -ENODEV;
-               goto errout;
+               snd_opl3sa2_unregister_all();
+               return -ENODEV;
        }
        return 0;
-
- errout:
-       snd_opl3sa2_unregister_all();
-       return err;
 }
 
 static void __exit alsa_card_opl3sa2_exit(void)