fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / sound / oss / dmasound / dmasound_awacs.c
index 89f52a7..37773b1 100644 (file)
@@ -67,7 +67,6 @@
 
 #include <linux/types.h>
 #include <linux/module.h>
-#include <linux/config.h>
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/delay.h>
@@ -80,7 +79,7 @@
 #include <linux/kmod.h>
 #include <linux/interrupt.h>
 #include <linux/input.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 #ifdef CONFIG_ADB_CUDA
 #include <linux/cuda.h>
 #endif
@@ -88,8 +87,6 @@
 #include <linux/pmu.h>
 #endif
 
-#include <linux/i2c-dev.h>
-
 #include <asm/uaccess.h>
 #include <asm/prom.h>
 #include <asm/machdep.h>
@@ -125,11 +122,12 @@ static int awacs_rate_index;
 static int awacs_subframe;
 static struct device_node* awacs_node;
 static struct device_node* i2s_node;
+static struct resource awacs_rsrc[3];
 
 static char awacs_name[64];
 static int awacs_revision;
 static int awacs_sleeping;
-static DECLARE_MUTEX(dmasound_sem);
+static DEFINE_MUTEX(dmasound_mutex);
 
 static int sound_device_id;            /* exists after iMac revA */
 static int hw_can_byteswap = 1 ;       /* most pmac sound h/w can */
@@ -255,7 +253,7 @@ static int awacs_burgundy_read_mvolume(unsigned address);
 
 static volatile struct dbdma_cmd *emergency_dbdma_cmd;
 
-#ifdef CONFIG_PMAC_PBOOK
+#ifdef CONFIG_PM
 /*
  * Stuff for restoring after a sleep.
  */
@@ -263,7 +261,7 @@ static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when);
 struct pmu_sleep_notifier awacs_sleep_notifier = {
        awacs_sleep_notify, SLEEP_LEVEL_SOUND,
 };
-#endif /* CONFIG_PMAC_PBOOK */
+#endif /* CONFIG_PM */
 
 /* for (soft) sample rate translations */
 int expand_bal;                /* Balance factor for expanding (not volume!) */
@@ -271,7 +269,7 @@ int expand_read_bal;        /* Balance factor for expanding reads (not volume!) */
 
 /*** Low level stuff *********************************************************/
 
-static void *PMacAlloc(unsigned int size, int flags);
+static void *PMacAlloc(unsigned int size, gfp_t flags);
 static void PMacFree(void *ptr, unsigned int size);
 static int PMacIrqInit(void);
 #ifdef MODULE
@@ -283,9 +281,9 @@ static int PMacSetFormat(int format);
 static int PMacSetVolume(int volume);
 static void PMacPlay(void);
 static void PMacRecord(void);
-static irqreturn_t pmac_awacs_tx_intr(int irq, void *devid, struct pt_regs *regs);
-static irqreturn_t pmac_awacs_rx_intr(int irq, void *devid, struct pt_regs *regs);
-static irqreturn_t pmac_awacs_intr(int irq, void *devid, struct pt_regs *regs);
+static irqreturn_t pmac_awacs_tx_intr(int irq, void *devid);
+static irqreturn_t pmac_awacs_rx_intr(int irq, void *devid);
+static irqreturn_t pmac_awacs_intr(int irq, void *devid);
 static void awacs_write(int val);
 static int awacs_get_volume(int reg, int lshift);
 static int awacs_volume_setter(int volume, int n, int mute, int lshift);
@@ -311,11 +309,11 @@ extern int daca_enter_sleep(void);
 extern int daca_leave_sleep(void);
 
 #define TRY_LOCK()     \
-       if ((rc = down_interruptible(&dmasound_sem)) != 0)      \
+       if ((rc = mutex_lock_interruptible(&dmasound_mutex)) != 0)      \
                return rc;
-#define LOCK()         down(&dmasound_sem);
+#define LOCK()         mutex_lock(&dmasound_mutex);
 
-#define UNLOCK()       up(&dmasound_sem);
+#define UNLOCK()       mutex_unlock(&dmasound_mutex);
 
 /* We use different versions that the ones provided in dmasound.h
  * 
@@ -349,8 +347,8 @@ int
 setup_audio_gpio(const char *name, const char* compatible, int *gpio_addr, int* gpio_pol)
 {
        struct device_node *np;
-       u32* pp;
-       
+       const u32* pp;
+
        np = find_devices("gpio");
        if (!np)
                return -ENODEV;
@@ -358,7 +356,8 @@ setup_audio_gpio(const char *name, const char* compatible, int *gpio_addr, int*
        np = np->child;
        while(np != 0) {
                if (name) {
-                       char *property = get_property(np,"audio-gpio",NULL);
+                       const char *property =
+                               get_property(np,"audio-gpio",NULL);
                        if (property != 0 && strcmp(property,name) == 0)
                                break;
                } else if (compatible && device_is_compatible(np, compatible))
@@ -367,19 +366,16 @@ setup_audio_gpio(const char *name, const char* compatible, int *gpio_addr, int*
        }
        if (!np)
                return -ENODEV;
-       pp = (u32 *)get_property(np, "AAPL,address", NULL);
+       pp = get_property(np, "AAPL,address", NULL);
        if (!pp)
                return -ENODEV;
        *gpio_addr = (*pp) & 0x0000ffff;
-       pp = (u32 *)get_property(np, "audio-gpio-active-state", NULL);
+       pp = get_property(np, "audio-gpio-active-state", NULL);
        if (pp)
                *gpio_pol = *pp;
        else
                *gpio_pol = 1;
-       if (np->n_intrs > 0)
-               return np->intrs[0].line;
-       
-       return 0;
+       return irq_of_parse_and_map(np, 0);
 }
 
 static inline void
@@ -402,7 +398,7 @@ read_audio_gpio(int gpio_addr)
  * Headphone interrupt via GPIO (Tumbler, Snapper, DACA)
  */
 static irqreturn_t
-headphone_intr(int irq, void *devid, struct pt_regs *regs)
+headphone_intr(int irq, void *devid)
 {
        unsigned long flags;
 
@@ -469,7 +465,7 @@ tas_dmasound_init(void)
                        val = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, gpio_headphone_detect, 0);
                        pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, gpio_headphone_detect, val | 0x80);
                        /* Trigger it */
-                       headphone_intr(0,NULL,NULL);
+                       headphone_intr(0, NULL);
                }
        }
        if (!gpio_headphone_irq) {
@@ -614,7 +610,7 @@ tas_init_frame_rates(unsigned int *prop, unsigned int l)
 /*
  * PCI PowerMac, with AWACS, Screamer, Burgundy, DACA or Tumbler and DBDMA.
  */
-static void *PMacAlloc(unsigned int size, int flags)
+static void *PMacAlloc(unsigned int size, gfp_t flags)
 {
        return kmalloc(size, flags);
 }
@@ -667,19 +663,18 @@ static void PMacIrqCleanup(void)
        iounmap(awacs_txdma);
        iounmap(awacs_rxdma);
 
-       release_OF_resource(awacs_node, 0);
-       release_OF_resource(awacs_node, 1);
-       release_OF_resource(awacs_node, 2);
-
-       if (awacs_tx_cmd_space)
-               kfree(awacs_tx_cmd_space);
-       if (awacs_rx_cmd_space)
-               kfree(awacs_rx_cmd_space);
-       if (beep_dbdma_cmd_space)
-               kfree(beep_dbdma_cmd_space);
-       if (beep_buf)
-               kfree(beep_buf);
-#ifdef CONFIG_PMAC_PBOOK
+       release_mem_region(awacs_rsrc[0].start,
+                          awacs_rsrc[0].end - awacs_rsrc[0].start + 1);
+       release_mem_region(awacs_rsrc[1].start,
+                          awacs_rsrc[1].end - awacs_rsrc[1].start + 1);
+       release_mem_region(awacs_rsrc[2].start,
+                          awacs_rsrc[2].end - awacs_rsrc[2].start + 1);
+
+       kfree(awacs_tx_cmd_space);
+       kfree(awacs_rx_cmd_space);
+       kfree(beep_dbdma_cmd_space);
+       kfree(beep_buf);
+#ifdef CONFIG_PM
        pmu_unregister_sleep_notifier(&awacs_sleep_notifier);
 #endif
 }
@@ -1042,7 +1037,7 @@ static void PMacRecord(void)
 */
 
 static irqreturn_t
-pmac_awacs_tx_intr(int irq, void *devid, struct pt_regs *regs)
+pmac_awacs_tx_intr(int irq, void *devid)
 {
        int i = write_sq.front;
        int stat;
@@ -1134,7 +1129,7 @@ printk("dmasound_pmac: tx-irq: xfer died - patching it up...\n") ;
 
 
 static irqreturn_t
-pmac_awacs_rx_intr(int irq, void *devid, struct pt_regs *regs)
+pmac_awacs_rx_intr(int irq, void *devid)
 {
        int stat ;
        /* For some reason on my PowerBook G3, I get one interrupt
@@ -1217,7 +1212,7 @@ printk("dmasound_pmac: rx-irq: DIED - attempting resurection\n");
 
 
 static irqreturn_t
-pmac_awacs_intr(int irq, void *devid, struct pt_regs *regs)
+pmac_awacs_intr(int irq, void *devid)
 {
        int ctrl;
        int status;
@@ -1419,7 +1414,7 @@ load_awacs(void)
        }
 }
 
-#ifdef CONFIG_PMAC_PBOOK
+#ifdef CONFIG_PM
 /*
  * Save state when going to sleep, restore it afterwards.
  */
@@ -1504,7 +1499,7 @@ static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when)
                                write_audio_gpio(gpio_audio_reset, !gpio_audio_reset_pol);
                                msleep(150);
                                tas_leave_sleep(); /* Stub for now */
-                               headphone_intr(0,NULL,NULL);
+                               headphone_intr(0, NULL);
                                break;
                        case AWACS_DACA:
                                msleep(10); /* Check this !!! */
@@ -1555,13 +1550,13 @@ static int awacs_sleep_notify(struct pmu_sleep_notifier *self, int when)
        }
        return PBOOK_SLEEP_OK;
 }
-#endif /* CONFIG_PMAC_PBOOK */
+#endif /* CONFIG_PM */
 
 
 /* All the burgundy functions: */
 
 /* Waits for busy flag to clear */
-inline static void
+static inline void
 awacs_burgundy_busy_wait(void)
 {
        int count = 50; /* > 2 samples at 44k1 */
@@ -1569,7 +1564,7 @@ awacs_burgundy_busy_wait(void)
                udelay(1) ;
 }
 
-inline static void
+static inline void
 awacs_burgundy_extend_wait(void)
 {
        int count = 50 ; /* > 2 samples at 44k1 */
@@ -2301,8 +2296,7 @@ if (count <= 0)
 #endif
 
        if ((write_sq.max_count + 1) > number_of_tx_cmd_buffers) {
-               if (awacs_tx_cmd_space)
-                       kfree(awacs_tx_cmd_space);
+               kfree(awacs_tx_cmd_space);
                number_of_tx_cmd_buffers = 0;
 
                /* we need nbufs + 1 (for the loop) and we should request + 1
@@ -2360,8 +2354,7 @@ if (count <= 0)
 #endif
 
        if ((read_sq.max_count+1) > number_of_rx_cmd_buffers ) {
-               if (awacs_rx_cmd_space)
-                       kfree(awacs_rx_cmd_space);
+               kfree(awacs_rx_cmd_space);
                number_of_rx_cmd_buffers = 0;
 
                /* we need nbufs + 1 (for the loop) and we should request + 1 again
@@ -2802,32 +2795,23 @@ __init setup_beep(void)
                        DBDMA_ALIGN(beep_dbdma_cmd_space);
        /* set up emergency dbdma cmd */
        emergency_dbdma_cmd = beep_dbdma_cmd+1 ;
-       beep_buf = (short *) kmalloc(BEEP_BUFLEN * 4, GFP_KERNEL);
+       beep_buf = kmalloc(BEEP_BUFLEN * 4, GFP_KERNEL);
        if (beep_buf == NULL) {
                printk(KERN_ERR "dmasound_pmac: no memory for beep buffer\n");
-               if( beep_dbdma_cmd_space ) kfree(beep_dbdma_cmd_space) ;
+               kfree(beep_dbdma_cmd_space) ;
                return -ENOMEM ;
        }
        return 0 ;
 }
 
-static struct input_dev awacs_beep_dev = {
-       .evbit          = { BIT(EV_SND) },
-       .sndbit         = { BIT(SND_BELL) | BIT(SND_TONE) },
-       .event          = awacs_beep_event,
-       .name           = "dmasound beeper",
-       .phys           = "macio/input0", /* what the heck is this?? */
-       .id             = {
-               .bustype        = BUS_HOST,
-       },
-};
+static struct input_dev *awacs_beep_dev;
 
 int __init dmasound_awacs_init(void)
 {
        struct device_node *io = NULL, *info = NULL;
        int vol, res;
 
-       if (_machine != _MACH_Pmac)
+       if (!machine_is(powermac))
                return -ENODEV;
 
        awacs_subframe = 0;
@@ -2878,57 +2862,84 @@ printk("dmasound_pmac: couldn't find a Codec we can handle\n");
         * other info if necessary (early AWACS we want to read chip ids)
         */
 
-       if (io->n_addrs < 3 || io->n_intrs < 3) {
+       if (of_get_address(io, 2, NULL, NULL) == NULL) {
                /* OK - maybe we need to use the 'awacs' node (on earlier
                 * machines).
-               */
+                */
                if (awacs_node) {
                        io = awacs_node ;
-                       if (io->n_addrs < 3 || io->n_intrs < 3) {
-                               printk("dmasound_pmac: can't use %s"
-                                       " (%d addrs, %d intrs)\n",
-                                io->full_name, io->n_addrs, io->n_intrs);
+                       if (of_get_address(io, 2, NULL, NULL) == NULL) {
+                               printk("dmasound_pmac: can't use %s\n",
+                                      io->full_name);
                                return -ENODEV;
                        }
-               } else {
-                       printk("dmasound_pmac: can't use %s (%d addrs, %d intrs)\n",
-                             io->full_name, io->n_addrs, io->n_intrs);
-               }
+               } else
+                       printk("dmasound_pmac: can't use %s\n", io->full_name);
        }
 
-       if (!request_OF_resource(io, 0, NULL)) {
+       if (of_address_to_resource(io, 0, &awacs_rsrc[0]) ||
+           request_mem_region(awacs_rsrc[0].start,
+                              awacs_rsrc[0].end - awacs_rsrc[0].start + 1,
+                              " (IO)") == NULL) {
                printk(KERN_ERR "dmasound: can't request IO resource !\n");
                return -ENODEV;
        }
-       if (!request_OF_resource(io, 1, " (tx dma)")) {
-               release_OF_resource(io, 0);
-               printk(KERN_ERR "dmasound: can't request TX DMA resource !\n");
+       if (of_address_to_resource(io, 1, &awacs_rsrc[1]) ||
+           request_mem_region(awacs_rsrc[1].start,
+                              awacs_rsrc[1].end - awacs_rsrc[1].start + 1,
+                              " (tx dma)") == NULL) {
+               release_mem_region(awacs_rsrc[0].start,
+                                  awacs_rsrc[0].end - awacs_rsrc[0].start + 1);
+               printk(KERN_ERR "dmasound: can't request Tx DMA resource !\n");
                return -ENODEV;
        }
-
-       if (!request_OF_resource(io, 2, " (rx dma)")) {
-               release_OF_resource(io, 0);
-               release_OF_resource(io, 1);
-               printk(KERN_ERR "dmasound: can't request RX DMA resource !\n");
+       if (of_address_to_resource(io, 2, &awacs_rsrc[2]) ||
+           request_mem_region(awacs_rsrc[2].start,
+                              awacs_rsrc[2].end - awacs_rsrc[2].start + 1,
+                              " (rx dma)") == NULL) {
+               release_mem_region(awacs_rsrc[0].start,
+                                  awacs_rsrc[0].end - awacs_rsrc[0].start + 1);
+               release_mem_region(awacs_rsrc[1].start,
+                                  awacs_rsrc[1].end - awacs_rsrc[1].start + 1);
+               printk(KERN_ERR "dmasound: can't request Rx DMA resource !\n");
                return -ENODEV;
        }
 
+       awacs_beep_dev = input_allocate_device();
+       if (!awacs_beep_dev) {
+               release_mem_region(awacs_rsrc[0].start,
+                                  awacs_rsrc[0].end - awacs_rsrc[0].start + 1);
+               release_mem_region(awacs_rsrc[1].start,
+                                  awacs_rsrc[1].end - awacs_rsrc[1].start + 1);
+               release_mem_region(awacs_rsrc[2].start,
+                                  awacs_rsrc[2].end - awacs_rsrc[2].start + 1);
+               printk(KERN_ERR "dmasound: can't allocate input device !\n");
+               return -ENOMEM;
+       }
+
+       awacs_beep_dev->name = "dmasound beeper";
+       awacs_beep_dev->phys = "macio/input0";
+       awacs_beep_dev->id.bustype = BUS_HOST;
+       awacs_beep_dev->event = awacs_beep_event;
+       awacs_beep_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
+       awacs_beep_dev->evbit[0] = BIT(EV_SND);
+
        /* all OF versions I've seen use this value */
        if (i2s_node)
-               i2s = ioremap(io->addrs[0].address, 0x1000);
+               i2s = ioremap(awacs_rsrc[0].start, 0x1000);
        else
-               awacs = ioremap(io->addrs[0].address, 0x1000);
-       awacs_txdma = ioremap(io->addrs[1].address, 0x100);
-       awacs_rxdma = ioremap(io->addrs[2].address, 0x100);
+               awacs = ioremap(awacs_rsrc[0].start, 0x1000);
+       awacs_txdma = ioremap(awacs_rsrc[1].start, 0x100);
+       awacs_rxdma = ioremap(awacs_rsrc[2].start, 0x100);
 
        /* first of all make sure that the chip is powered up....*/
        pmac_call_feature(PMAC_FTR_SOUND_CHIP_ENABLE, io, 0, 1);
        if (awacs_revision == AWACS_SCREAMER && awacs)
                awacs_recalibrate();
 
-       awacs_irq = io->intrs[0].line;
-       awacs_tx_irq = io->intrs[1].line;
-       awacs_rx_irq = io->intrs[2].line;
+       awacs_irq = irq_of_parse_and_map(io, 0);
+       awacs_tx_irq = irq_of_parse_and_map(io, 1);
+       awacs_rx_irq = irq_of_parse_and_map(io, 2);
 
        /* Hack for legacy crap that will be killed someday */
        awacs_node = io;
@@ -2987,10 +2998,13 @@ printk("dmasound_pmac: Awacs/Screamer Codec Mfct: %d Rev %d\n", mfg, rev);
 
        set_hw_byteswap(io) ; /* figure out if the h/w can do it */
 
-       /* get default volume from nvram
-        * vol = (~nvram_read_byte(0x1308) & 7) << 1;
-       */
+#ifdef CONFIG_NVRAM
+       /* get default volume from nvram */
        vol = ((pmac_xpram_read( 8 ) & 7 ) << 1 );
+#else
+       vol = 0;
+#endif
+
        /* set up tracking values */
        spk_vol = vol * 100 ;
        spk_vol /= 7 ; /* get set value to a percentage */
@@ -3056,9 +3070,9 @@ printk("dmasound_pmac: Awacs/Screamer Codec Mfct: %d Rev %d\n", mfg, rev);
        if ((res=setup_beep()))
                return res ;
 
-#ifdef CONFIG_PMAC_PBOOK
+#ifdef CONFIG_PM
        pmu_register_sleep_notifier(&awacs_sleep_notifier);
-#endif /* CONFIG_PMAC_PBOOK */
+#endif /* CONFIG_PM */
 
        /* Powerbooks have odd ways of enabling inputs such as
           an expansion-bay CD or sound from an internal modem
@@ -3079,9 +3093,10 @@ printk("dmasound_pmac: Awacs/Screamer Codec Mfct: %d Rev %d\n", mfg, rev);
                struct device_node* mio;
                macio_base = NULL;
                for (mio = io->parent; mio; mio = mio->parent) {
-                       if (strcmp(mio->name, "mac-io") == 0
-                           && mio->n_addrs > 0) {
-                               macio_base = ioremap(mio->addrs[0].address, 0x40);
+                       if (strcmp(mio->name, "mac-io") == 0) {
+                               struct resource r;
+                               if (of_address_to_resource(mio, 0, &r) == 0)
+                                       macio_base = ioremap(r.start, 0x40);
                                break;
                        }
                }
@@ -3143,14 +3158,14 @@ printk("dmasound_pmac: Awacs/Screamer Codec Mfct: %d Rev %d\n", mfg, rev);
         * XXX: we should handle errors here, but that would mean
         * rewriting the whole init code.  later..
         */
-       input_register_device(&awacs_beep_dev);
+       input_register_device(awacs_beep_dev);
 
        return dmasound_init();
 }
 
 static void __exit dmasound_awacs_cleanup(void)
 {
-       input_unregister_device(&awacs_beep_dev);
+       input_unregister_device(awacs_beep_dev);
 
        switch (awacs_revision) {
                case AWACS_TUMBLER: