vsprintf: use TOLOWER whenever possible
[safe/jmp/linux-2.6] / sound / isa / opl3sa2.c
index 854a9f7..0481a55 100644 (file)
@@ -28,7 +28,7 @@
 #include <linux/pnp.h>
 #include <linux/moduleparam.h>
 #include <sound/core.h>
-#include <sound/cs4231.h>
+#include <sound/wss.h>
 #include <sound/mpu401.h>
 #include <sound/opl3.h>
 #include <sound/initval.h>
@@ -124,7 +124,6 @@ static int pnpc_registered;
 #define OPL3SA2_PM_D3  (OPL3SA2_PM_ADOWN|OPL3SA2_PM_PSV|OPL3SA2_PM_PDN|OPL3SA2_PM_PDX)
 
 struct snd_opl3sa2 {
-       struct snd_card *card;
        int version;            /* 2 or 3 */
        unsigned long port;     /* control port */
        struct resource *res_port; /* control port resource */
@@ -133,7 +132,7 @@ struct snd_opl3sa2 {
        spinlock_t reg_lock;
        struct snd_hwdep *synth;
        struct snd_rawmidi *rmidi;
-       struct snd_cs4231 *cs4231;
+       struct snd_wss *wss;
        unsigned char ctlregs[0x20];
        int ymode;              /* SL added */
        struct snd_kcontrol *master_switch;
@@ -180,12 +179,13 @@ static unsigned char __snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char
        unsigned char result;
 #if 0
        outb(0x1d, port);       /* password */
-       printk("read [0x%lx] = 0x%x\n", port, inb(port));
+       printk(KERN_DEBUG "read [0x%lx] = 0x%x\n", port, inb(port));
 #endif
        outb(reg, chip->port);  /* register */
        result = inb(chip->port + 1);
 #if 0
-       printk("read [0x%lx] = 0x%x [0x%x]\n", port, result, inb(port));
+       printk(KERN_DEBUG "read [0x%lx] = 0x%x [0x%x]\n",
+              port, result, inb(port));
 #endif
        return result;
 }
@@ -222,20 +222,22 @@ static void snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsig
        spin_unlock_irqrestore(&chip->reg_lock, flags);
 }
 
-static int __devinit snd_opl3sa2_detect(struct snd_opl3sa2 *chip)
+static int __devinit snd_opl3sa2_detect(struct snd_card *card)
 {
-       struct snd_card *card;
+       struct snd_opl3sa2 *chip = card->private_data;
        unsigned long port;
        unsigned char tmp, tmp1;
        char str[2];
 
-       card = chip->card;
        port = chip->port;
        if ((chip->res_port = request_region(port, 2, "OPL3-SA control")) == NULL) {
                snd_printk(KERN_ERR PFX "can't grab port 0x%lx\n", port);
                return -EBUSY;
        }
-       // snd_printk("REG 0A = 0x%x\n", snd_opl3sa2_read(chip, 0x0a));
+       /*
+       snd_printk(KERN_DEBUG "REG 0A = 0x%x\n",
+                  snd_opl3sa2_read(chip, 0x0a));
+       */
        chip->version = 0;
        tmp = snd_opl3sa2_read(chip, OPL3SA2_MISC);
        if (tmp == 0xff) {
@@ -298,12 +300,14 @@ static int __devinit snd_opl3sa2_detect(struct snd_opl3sa2 *chip)
 static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id)
 {
        unsigned short status;
-       struct snd_opl3sa2 *chip = dev_id;
+       struct snd_card *card = dev_id;
+       struct snd_opl3sa2 *chip;
        int handled = 0;
 
-       if (chip == NULL || chip->card == NULL)
+       if (card == NULL)
                return IRQ_NONE;
 
+       chip = card->private_data;
        status = snd_opl3sa2_read(chip, OPL3SA2_IRQ_STATUS);
 
        if (status & 0x20) {
@@ -318,7 +322,7 @@ static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id)
 
        if (status & 0x07) {    /* TI,CI,PI */
                handled = 1;
-               snd_cs4231_interrupt(irq, chip->cs4231);
+               snd_wss_interrupt(irq, chip->wss);
        }
 
        if (status & 0x40) { /* hardware volume change */
@@ -327,8 +331,10 @@ static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id)
                snd_opl3sa2_read(chip, OPL3SA2_MASTER_RIGHT);
                snd_opl3sa2_read(chip, OPL3SA2_MASTER_LEFT);
                if (chip->master_switch && chip->master_volume) {
-                       snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id);
-                       snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_volume->id);
+                       snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
+                                       &chip->master_switch->id);
+                       snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
+                                       &chip->master_volume->id);
                }
        }
        return IRQ_RETVAL(handled);
@@ -336,29 +342,18 @@ static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id)
 
 #define OPL3SA2_SINGLE(xname, xindex, reg, shift, mask, invert) \
 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
-  .info = snd_opl3sa2_info_single, \
+  .info = snd_wss_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, \
+  .info = snd_wss_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)
-{
-       int mask = (kcontrol->private_value >> 16) & 0xff;
-
-       uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = mask;
-       return 0;
-}
-
 static int snd_opl3sa2_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol);
@@ -402,29 +397,18 @@ static int snd_opl3sa2_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_
 
 #define OPL3SA2_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
-  .info = snd_opl3sa2_info_double, \
+  .info = snd_wss_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, \
+  .info = snd_wss_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)
-{
-       int mask = (kcontrol->private_value >> 24) & 0xff;
-
-       uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
-       uinfo->count = 2;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = mask;
-       return 0;
-}
-
 static int snd_opl3sa2_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol);
@@ -497,6 +481,7 @@ OPL3SA2_DOUBLE_TLV("Master Playback Volume", 0, 0x07, 0x08, 0, 0, 15, 1,
 OPL3SA2_SINGLE("Mic Playback Switch", 0, 0x09, 7, 1, 1),
 OPL3SA2_SINGLE_TLV("Mic Playback Volume", 0, 0x09, 0, 31, 1,
                   db_scale_5bit_12db_max),
+OPL3SA2_SINGLE("ZV Port Switch", 0, 0x02, 0, 1, 0),
 };
 
 static struct snd_kcontrol_new snd_opl3sa2_tone_controls[] = {
@@ -512,9 +497,9 @@ static void snd_opl3sa2_master_free(struct snd_kcontrol *kcontrol)
        chip->master_volume = NULL;
 }
 
-static int __devinit snd_opl3sa2_mixer(struct snd_opl3sa2 *chip)
+static int __devinit snd_opl3sa2_mixer(struct snd_card *card)
 {
-       struct snd_card *card = chip->card;
+       struct snd_opl3sa2 *chip = card->private_data;
        struct snd_ctl_elem_id id1, id2;
        struct snd_kcontrol *kctl;
        unsigned int idx;
@@ -570,21 +555,27 @@ static int __devinit snd_opl3sa2_mixer(struct snd_opl3sa2 *chip)
 #ifdef CONFIG_PM
 static int snd_opl3sa2_suspend(struct snd_card *card, pm_message_t state)
 {
-       struct snd_opl3sa2 *chip = card->private_data;
+       if (card) {
+               struct snd_opl3sa2 *chip = card->private_data;
 
-       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
-       chip->cs4231->suspend(chip->cs4231);
-       /* power down */
-       snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D3);
+               snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+               chip->wss->suspend(chip->wss);
+               /* power down */
+               snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D3);
+       }
 
        return 0;
 }
 
 static int snd_opl3sa2_resume(struct snd_card *card)
 {
-       struct snd_opl3sa2 *chip = card->private_data;
+       struct snd_opl3sa2 *chip;
        int i;
 
+       if (!card)
+               return 0;
+
+       chip = card->private_data;
        /* power up */
        snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D0);
 
@@ -597,8 +588,8 @@ static int snd_opl3sa2_resume(struct snd_card *card)
                for (i = 0x12; i <= 0x16; i++)
                        snd_opl3sa2_write(chip, i, chip->ctlregs[i]);
        }
-       /* restore cs4231 */
-       chip->cs4231->resume(chip->cs4231);
+       /* restore wss */
+       chip->wss->resume(chip->wss);
 
        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
        return 0;
@@ -633,33 +624,35 @@ static void snd_opl3sa2_free(struct snd_card *card)
 {
        struct snd_opl3sa2 *chip = card->private_data;
        if (chip->irq >= 0)
-               free_irq(chip->irq, (void *)chip);
+               free_irq(chip->irq, card);
        release_and_free_resource(chip->res_port);
 }
 
-static struct snd_card *snd_opl3sa2_card_new(int dev)
+static int snd_opl3sa2_card_new(int dev, struct snd_card **cardp)
 {
        struct snd_card *card;
        struct snd_opl3sa2 *chip;
+       int err;
 
-       card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct snd_opl3sa2));
-       if (card == NULL)
-               return NULL;
+       err = snd_card_create(index[dev], id[dev], THIS_MODULE,
+                             sizeof(struct snd_opl3sa2), &card);
+       if (err < 0)
+               return err;
        strcpy(card->driver, "OPL3SA2");
-       strcpy(card->shortname, "Yamaha OPL3-SA2");
+       strcpy(card->shortname, "Yamaha OPL3-SA");
        chip = card->private_data;
        spin_lock_init(&chip->reg_lock);
        chip->irq = -1;
-       chip->card = card;
        card->private_free = snd_opl3sa2_free;
-       return card;
+       *cardp = card;
+       return 0;
 }
 
 static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev)
 {
        int xirq, xdma1, xdma2;
        struct snd_opl3sa2 *chip;
-       struct snd_cs4231 *cs4231;
+       struct snd_wss *wss;
        struct snd_opl3 *opl3;
        int err;
 
@@ -672,30 +665,36 @@ static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev)
        xdma2 = dma2[dev];
        if (xdma2 < 0)
                chip->single_dma = 1;
-       if ((err = snd_opl3sa2_detect(chip)) < 0)
+       err = snd_opl3sa2_detect(card);
+       if (err < 0)
                return err;
-       if (request_irq(xirq, snd_opl3sa2_interrupt, IRQF_DISABLED, "OPL3-SA2", chip)) {
+       err = request_irq(xirq, snd_opl3sa2_interrupt, IRQF_DISABLED,
+                         "OPL3-SA2", card);
+       if (err) {
                snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq);
                return -ENODEV;
        }
        chip->irq = xirq;
-       if ((err = snd_cs4231_create(card,
-                                    wss_port[dev] + 4, -1,
-                                    xirq, xdma1, xdma2,
-                                    CS4231_HW_OPL3SA2,
-                                    CS4231_HWSHARE_IRQ,
-                                    &cs4231)) < 0) {
+       err = snd_wss_create(card,
+                            wss_port[dev] + 4, -1,
+                            xirq, xdma1, xdma2,
+                            WSS_HW_OPL3SA2, WSS_HWSHARE_IRQ, &wss);
+       if (err < 0) {
                snd_printd("Oops, WSS not detected at 0x%lx\n", wss_port[dev] + 4);
                return err;
        }
-       chip->cs4231 = cs4231;
-       if ((err = snd_cs4231_pcm(cs4231, 0, NULL)) < 0)
+       chip->wss = wss;
+       err = snd_wss_pcm(wss, 0, NULL);
+       if (err < 0)
                return err;
-       if ((err = snd_cs4231_mixer(cs4231)) < 0)
+       err = snd_wss_mixer(wss);
+       if (err < 0)
                return err;
-       if ((err = snd_opl3sa2_mixer(chip)) < 0)
+       err = snd_opl3sa2_mixer(card);
+       if (err < 0)
                return err;
-       if ((err = snd_cs4231_timer(cs4231, 0, NULL)) < 0)
+       err = snd_wss_timer(wss, 0, NULL);
+       if (err < 0)
                return err;
        if (fm_port[dev] >= 0x340 && fm_port[dev] < 0x400) {
                if ((err = snd_opl3_create(card, fm_port[dev],
@@ -738,9 +737,9 @@ static int __devinit snd_opl3sa2_pnp_detect(struct pnp_dev *pdev,
        if (dev >= SNDRV_CARDS)
                return -ENODEV;
 
-       card = snd_opl3sa2_card_new(dev);
-       if (! card)
-               return -ENOMEM;
+       err = snd_opl3sa2_card_new(dev, &card);
+       if (err < 0)
+               return err;
        if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) {
                snd_card_free(card);
                return err;
@@ -804,9 +803,9 @@ static int __devinit snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard,
        if (dev >= SNDRV_CARDS)
                return -ENODEV;
 
-       card = snd_opl3sa2_card_new(dev);
-       if (! card)
-               return -ENOMEM;
+       err = snd_opl3sa2_card_new(dev, &card);
+       if (err < 0)
+               return err;
        if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) {
                snd_card_free(card);
                return err;
@@ -885,9 +884,9 @@ static int __devinit snd_opl3sa2_isa_probe(struct device *pdev,
        struct snd_card *card;
        int err;
 
-       card = snd_opl3sa2_card_new(dev);
-       if (! card)
-               return -ENOMEM;
+       err = snd_opl3sa2_card_new(dev, &card);
+       if (err < 0)
+               return err;
        snd_card_set_dev(card, pdev);
        if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
                snd_card_free(card);