vserver 1.9.5.x5
[linux-2.6.git] / sound / sparc / cs4231.c
index fb0ef1a..36f9fe4 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
+#include <linux/moduleparam.h>
 
 #include <sound/driver.h>
 #include <sound/core.h>
@@ -22,7 +23,6 @@
 #include <sound/info.h>
 #include <sound/control.h>
 #include <sound/timer.h>
-#define SNDRV_GET_ID
 #include <sound/initval.h>
 #include <sound/pcm_params.h>
 
@@ -50,24 +50,20 @@ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;  /* Index 0-MAX */
 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable this card */
 
-MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for Sun CS4231 soundcard.");
-MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
-MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
+module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for Sun CS4231 soundcard.");
-MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
-MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable Sun CS4231 soundcard.");
-MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
 MODULE_AUTHOR("Jaroslav Kysela, Derrick J. Brashear and David S. Miller");
 MODULE_DESCRIPTION("Sun CS4231");
 MODULE_LICENSE("GPL");
-MODULE_CLASSES("{sound}");
-MODULE_DEVICES("{{Sun,CS4231}}");
+MODULE_SUPPORTED_DEVICE("{{Sun,CS4231}}");
 
 typedef struct snd_cs4231 {
        spinlock_t              lock;
-       unsigned long           port;
+       void __iomem            *port;
 #ifdef EBUS_SUPPORT
        struct ebus_dma_info    eb2c;
        struct ebus_dma_info    eb2p;
@@ -111,7 +107,6 @@ typedef struct snd_cs4231 {
        unsigned int            regs_size;
        struct snd_cs4231       *next;
 } cs4231_t;
-#define chip_t cs4231_t
 
 static cs4231_t *cs4231_list;
 
@@ -361,7 +356,7 @@ static unsigned char snd_cs4231_original_image[32] =
        0x00,                   /* 1f/31 - cbrl */
 };
 
-static u8 __cs4231_readb(cs4231_t *cp, unsigned long reg_addr)
+static u8 __cs4231_readb(cs4231_t *cp, void __iomem *reg_addr)
 {
 #ifdef EBUS_SUPPORT
        if (cp->flags & CS4231_FLAG_EBUS) {
@@ -376,7 +371,7 @@ static u8 __cs4231_readb(cs4231_t *cp, unsigned long reg_addr)
 #endif
 }
 
-static void __cs4231_writeb(cs4231_t *cp, u8 val, unsigned long reg_addr)
+static void __cs4231_writeb(cs4231_t *cp, u8 val, void __iomem *reg_addr)
 {
 #ifdef EBUS_SUPPORT
        if (cp->flags & CS4231_FLAG_EBUS) {
@@ -395,7 +390,7 @@ static void __cs4231_writeb(cs4231_t *cp, u8 val, unsigned long reg_addr)
  *  Basic I/O functions
  */
 
-void snd_cs4231_outm(cs4231_t *chip, unsigned char reg,
+static void snd_cs4231_outm(cs4231_t *chip, unsigned char reg,
                     unsigned char mask, unsigned char value)
 {
        int timeout;
@@ -478,9 +473,9 @@ static unsigned char snd_cs4231_in(cs4231_t *chip, unsigned char reg)
        return ret;
 }
 
-#ifdef CONFIG_SND_DEBUG
+#if 0
 
-void snd_cs4231_debug(cs4231_t *chip)
+static void snd_cs4231_debug(cs4231_t *chip)
 {
        printk("CS4231 REGS:      INDEX = 0x%02x  ",
               __cs4231_readb(chip, CS4231P(chip, REGSEL)));
@@ -555,7 +550,7 @@ static void snd_cs4231_mce_up(cs4231_t *chip)
        chip->mce_bit |= CS4231_MCE;
        timeout = __cs4231_readb(chip, CS4231P(chip, REGSEL));
        if (timeout == 0x80)
-               snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
+               snd_printk("mce_up [%p]: serious init problem - codec still busy\n", chip->port);
        if (!(timeout & CS4231_MCE))
                __cs4231_writeb(chip, chip->mce_bit | (timeout & 0x1f), CS4231P(chip, REGSEL));
        spin_unlock_irqrestore(&chip->lock, flags);
@@ -565,7 +560,6 @@ static void snd_cs4231_mce_down(cs4231_t *chip)
 {
        unsigned long flags;
        int timeout;
-       signed long time;
 
        spin_lock_irqsave(&chip->lock, flags);
        snd_cs4231_busy_wait(chip);
@@ -574,13 +568,13 @@ static void snd_cs4231_mce_down(cs4231_t *chip)
 #endif
 #ifdef CONFIG_SND_DEBUG
        if (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT)
-               snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", CS4231P(chip, REGSEL));
+               snd_printk("mce_down [%p] - auto calibration time out (0)\n", CS4231P(chip, REGSEL));
 #endif
        chip->mce_bit &= ~CS4231_MCE;
        timeout = __cs4231_readb(chip, CS4231P(chip, REGSEL));
        __cs4231_writeb(chip, chip->mce_bit | (timeout & 0x1f), CS4231P(chip, REGSEL));
        if (timeout == 0x80)
-               snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
+               snd_printk("mce_down [%p]: serious init problem - codec still busy\n", chip->port);
        if ((timeout & CS4231_MCE) == 0) {
                spin_unlock_irqrestore(&chip->lock, flags);
                return;
@@ -599,29 +593,29 @@ static void snd_cs4231_mce_down(cs4231_t *chip)
 #if 0
        printk("(2) timeout = %i, jiffies = %li\n", timeout, jiffies);
 #endif
-       time = HZ / 4;
+       /* in 10ms increments, check condition, up to 250ms */
+       timeout = 25;
        while (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) {
                spin_unlock_irqrestore(&chip->lock, flags);
-               if (time <= 0) {
+               if (--timeout < 0) {
                        snd_printk("mce_down - auto calibration time out (2)\n");
                        return;
                }
-               set_current_state(TASK_INTERRUPTIBLE);
-               time = schedule_timeout(time);
+               msleep(10);
                spin_lock_irqsave(&chip->lock, flags);
        }
 #if 0
        printk("(3) jiffies = %li\n", jiffies);
 #endif
-       time = HZ / 10;
+       /* in 10ms increments, check condition, up to 100ms */
+       timeout = 10;
        while (__cs4231_readb(chip, CS4231P(chip, REGSEL)) & CS4231_INIT) {
                spin_unlock_irqrestore(&chip->lock, flags);
-               if (time <= 0) {
+               if (--timeout < 0) {
                        snd_printk("mce_down - auto calibration time out (3)\n");
                        return;
                }
-               set_current_state(TASK_INTERRUPTIBLE);          
-               time = schedule_timeout(time);
+               msleep(10);
                spin_lock_irqsave(&chip->lock, flags);
        }
        spin_unlock_irqrestore(&chip->lock, flags);
@@ -1231,7 +1225,7 @@ static void snd_cs4231_generic_interrupt(cs4231_t *chip)
 #ifdef SBUS_SUPPORT
 static irqreturn_t snd_cs4231_sbus_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
-       cs4231_t *chip = snd_magic_cast(cs4231_t, dev_id, return);
+       cs4231_t *chip = dev_id;
        u32 csr;
 
        csr = sbus_readl(chip->port + APCCSR);
@@ -1255,7 +1249,7 @@ static irqreturn_t snd_cs4231_sbus_interrupt(int irq, void *dev_id, struct pt_re
 #ifdef EBUS_SUPPORT
 static void snd_cs4231_ebus_play_callback(struct ebus_dma_info *p, int event, void *cookie)
 {
-       cs4231_t *chip = snd_magic_cast(cs4231_t, cookie, return);
+       cs4231_t *chip = cookie;
 
        if (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE) {
                snd_pcm_period_elapsed(chip->playback_substream);
@@ -1266,7 +1260,7 @@ static void snd_cs4231_ebus_play_callback(struct ebus_dma_info *p, int event, vo
 
 static void snd_cs4231_ebus_capture_callback(struct ebus_dma_info *p, int event, void *cookie)
 {
-       cs4231_t *chip = snd_magic_cast(cs4231_t, cookie, return);
+       cs4231_t *chip = cookie;
 
        if (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) {
                snd_pcm_period_elapsed(chip->capture_substream);
@@ -1352,7 +1346,7 @@ static int snd_cs4231_probe(cs4231_t *chip)
                                break;  /* this is valid value */
                }
        }
-       snd_printdd("cs4231: port = 0x%lx, id = 0x%x\n", chip->port, id);
+       snd_printdd("cs4231: port = %p, id = 0x%x\n", chip->port, id);
        if (id != 0x0a)
                return -ENODEV; /* no valid device found */
 
@@ -1546,7 +1540,7 @@ static snd_pcm_ops_t snd_cs4231_capture_ops = {
 
 static void snd_cs4231_pcm_free(snd_pcm_t *pcm)
 {
-       cs4231_t *chip = snd_magic_cast(cs4231_t, pcm->private_data, return);
+       cs4231_t *chip = pcm->private_data;
        chip->pcm = NULL;
        snd_pcm_lib_preallocate_free_for_all(pcm);
 }
@@ -1591,7 +1585,7 @@ int snd_cs4231_pcm(cs4231_t *chip)
 
 static void snd_cs4231_timer_free(snd_timer_t *timer)
 {
-       cs4231_t *chip = snd_magic_cast(cs4231_t, timer->private_data, return);
+       cs4231_t *chip = timer->private_data;
        chip->timer = NULL;
 }
 
@@ -1820,8 +1814,6 @@ int snd_cs4231_put_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontr
        return change;
 }
 
-#define CS4231_CONTROLS (sizeof(snd_cs4231_controls)/sizeof(snd_kcontrol_new_t))
-
 #define CS4231_SINGLE(xname, xindex, reg, shift, mask, invert) \
 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
   .info = snd_cs4231_info_single, \
@@ -1874,7 +1866,7 @@ int snd_cs4231_mixer(cs4231_t *chip)
 
        strcpy(card->mixername, chip->pcm->name);
 
-       for (idx = 0; idx < CS4231_CONTROLS; idx++) {
+       for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) {
                if ((err = snd_ctl_add(card,
                                       snd_ctl_new1(&snd_cs4231_controls[idx],
                                                    chip))) < 0)
@@ -1949,14 +1941,14 @@ static int snd_cs4231_sbus_free(cs4231_t *chip)
        if (chip->timer)
                snd_device_free(chip->card, chip->timer);
 
-       snd_magic_kfree(chip);
+       kfree(chip);
 
        return 0;
 }
 
 static int snd_cs4231_sbus_dev_free(snd_device_t *device)
 {
-       cs4231_t *cp = snd_magic_cast(cs4231_t, device->device_data, return -ENXIO);
+       cs4231_t *cp = device->device_data;
 
        return snd_cs4231_sbus_free(cp);
 }
@@ -1974,7 +1966,7 @@ static int __init snd_cs4231_sbus_create(snd_card_t *card,
        int err;
 
        *rchip = NULL;
-       chip = snd_magic_kcalloc(cs4231_t, 0, GFP_KERNEL);
+       chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
        if (chip == NULL)
                return -ENOMEM;
 
@@ -2063,14 +2055,14 @@ static int snd_cs4231_ebus_free(cs4231_t *chip)
        if (chip->timer)
                snd_device_free(chip->card, chip->timer);
 
-       snd_magic_kfree(chip);
+       kfree(chip);
 
        return 0;
 }
 
 static int snd_cs4231_ebus_dev_free(snd_device_t *device)
 {
-       cs4231_t *cp = snd_magic_cast(cs4231_t, device->device_data, return -ENXIO);
+       cs4231_t *cp = device->device_data;
 
        return snd_cs4231_ebus_free(cp);
 }
@@ -2088,7 +2080,7 @@ static int __init snd_cs4231_ebus_create(snd_card_t *card,
        int err;
 
        *rchip = NULL;
-       chip = snd_magic_kcalloc(cs4231_t, 0, GFP_KERNEL);
+       chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
        if (chip == NULL)
                return -ENOMEM;
 
@@ -2113,9 +2105,9 @@ static int __init snd_cs4231_ebus_create(snd_card_t *card,
        chip->eb2p.client_cookie = chip;
        chip->eb2p.irq = edev->irqs[1];
 
-       chip->port = (unsigned long) ioremap(edev->resource[0].start, 0x10);
-       chip->eb2p.regs = (unsigned long) ioremap(edev->resource[1].start, 0x10);
-       chip->eb2c.regs = (unsigned long) ioremap(edev->resource[2].start, 0x10);
+       chip->port = ioremap(edev->resource[0].start, 0x10);
+       chip->eb2p.regs = ioremap(edev->resource[1].start, 0x10);
+       chip->eb2c.regs = ioremap(edev->resource[2].start, 0x10);
        if (!chip->port || !chip->eb2p.regs || !chip->eb2c.regs) {
                snd_cs4231_ebus_free(chip);
                snd_printk("cs4231-%d: Unable to map chip registers.\n", dev);
@@ -2251,24 +2243,3 @@ static void __exit cs4231_exit(void)
 
 module_init(cs4231_init);
 module_exit(cs4231_exit);
-
-#ifndef MODULE
-
-/* format is: snd-sun-cs4231=index,id,enable */
-
-static int __init alsa_card_sun_cs4231_setup(char *str)
-{
-       static unsigned __initdata nr_dev = 0;
-
-       if (nr_dev >= SNDRV_CARDS)
-               return 0;
-       (void)(get_option(&str,&index[nr_dev]) == 2 &&
-              get_option(&str,&id[nr_dev]) == 2 &&
-              get_id(&str,&enable[nr_dev]) == 2);
-       nr_dev++;
-       return 1;
-}
-
-__setup("snd-sun-cs4231=", alsa_card_sun_cs4231_setup);
-
-#endif /* ifndef MODULE */