]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/macintosh/mediabay.c
macintosh/media bay: Convert semaphore to mutex
[net-next-2.6.git] / drivers / macintosh / mediabay.c
index bd8a1d14b45d1e1273f0271f5b195a9ae7665092..b1e5b4705250472a2819da9537fff2422e3ef967 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/init.h>
 #include <linux/ide.h>
 #include <linux/kthread.h>
+#include <linux/mutex.h>
 #include <asm/prom.h>
 #include <asm/pgtable.h>
 #include <asm/io.h>
@@ -77,13 +78,14 @@ struct media_bay_info {
        int                             index;
        int                             cached_gpio;
        int                             sleeping;
-       struct semaphore                lock;
+       struct mutex                    lock;
 #ifdef CONFIG_BLK_DEV_IDE_PMAC
+       ide_hwif_t                      *cd_port;
        void __iomem                    *cd_base;
        int                             cd_irq;
        int                             cd_retry;
 #endif
-#if defined(CONFIG_BLK_DEV_IDE_PMAC) || defined(CONFIG_MAC_FLOPPY)
+#if defined(CONFIG_BLK_DEV_IDE_PMAC)
        int                             cd_index;
 #endif
 };
@@ -416,6 +418,7 @@ static void poll_media_bay(struct media_bay_info* bay)
        }
 }
 
+#ifdef CONFIG_BLK_DEV_IDE_PMAC
 int check_media_bay(struct device_node *which_bay, int what)
 {
        int     i;
@@ -431,7 +434,6 @@ int check_media_bay(struct device_node *which_bay, int what)
 }
 EXPORT_SYMBOL(check_media_bay);
 
-#ifdef CONFIG_BLK_DEV_IDE_PMAC
 int check_media_bay_by_base(unsigned long base, int what)
 {
        int     i;
@@ -448,7 +450,7 @@ int check_media_bay_by_base(unsigned long base, int what)
 }
 
 int media_bay_set_ide_infos(struct device_node* which_bay, unsigned long base,
-                           int irq, int index)
+                           int irq, ide_hwif_t *hwif)
 {
        int     i;
 
@@ -456,28 +458,29 @@ int media_bay_set_ide_infos(struct device_node* which_bay, unsigned long base,
                struct media_bay_info* bay = &media_bays[i];
 
                if (bay->mdev && which_bay == bay->mdev->ofdev.node) {
-                       int timeout = 5000;
+                       int timeout = 5000, index = hwif->index;
                        
-                       down(&bay->lock);
+                       mutex_lock(&bay->lock);
 
+                       bay->cd_port    = hwif;
                        bay->cd_base    = (void __iomem *) base;
                        bay->cd_irq     = irq;
 
                        if ((MB_CD != bay->content_id) || bay->state != mb_up) {
-                               up(&bay->lock);
+                               mutex_unlock(&bay->lock);
                                return 0;
                        }
                        printk(KERN_DEBUG "Registered ide%d for media bay %d\n", index, i);
                        do {
                                if (MB_IDE_READY(i)) {
                                        bay->cd_index   = index;
-                                       up(&bay->lock);
+                                       mutex_unlock(&bay->lock);
                                        return 0;
                                }
                                mdelay(1);
                        } while(--timeout);
                        printk(KERN_DEBUG "Timeount waiting IDE in bay %d\n", i);
-                       up(&bay->lock);
+                       mutex_unlock(&bay->lock);
                        return -ENODEV;
                }
        }
@@ -551,15 +554,11 @@ static void media_bay_step(int i)
                        bay->timer = 0;
                        bay->state = mb_up;
                        if (bay->cd_index < 0) {
-                               hw_regs_t hw;
-
                                printk("mediabay %d, registering IDE...\n", i);
                                pmu_suspend();
-                               ide_init_hwif_ports(&hw, (unsigned long) bay->cd_base, (unsigned long) 0, NULL);
-                               hw.irq = bay->cd_irq;
-                               hw.chipset = ide_pmac;
-                               bay->cd_index =
-                                       ide_register_hw(&hw, NULL, NULL);
+                               ide_port_scan(bay->cd_port);
+                               if (bay->cd_port->present)
+                                       bay->cd_index = bay->cd_port->index;
                                pmu_resume();
                        }
                        if (bay->cd_index == -1) {
@@ -589,7 +588,7 @@ static void media_bay_step(int i)
                if (bay->cd_index >= 0) {
                        printk(KERN_DEBUG "Unregistering mb %d ide, index:%d\n", i,
                               bay->cd_index);
-                       ide_unregister(bay->cd_index, 1, 1);
+                       ide_port_unregister_devices(bay->cd_port);
                        bay->cd_index = -1;
                }
                if (bay->cd_retry) {
@@ -619,10 +618,10 @@ static int media_bay_task(void *x)
 
        while (!kthread_should_stop()) {
                for (i = 0; i < media_bay_count; ++i) {
-                       down(&media_bays[i].lock);
+                       mutex_lock(&media_bays[i].lock);
                        if (!media_bays[i].sleeping)
                                media_bay_step(i);
-                       up(&media_bays[i].lock);
+                       mutex_unlock(&media_bays[i].lock);
                }
 
                msleep_interruptible(MB_POLL_DELAY);
@@ -662,7 +661,7 @@ static int __devinit media_bay_attach(struct macio_dev *mdev, const struct of_de
        bay->index = i;
        bay->ops = match->data;
        bay->sleeping = 0;
-       init_MUTEX(&bay->lock);
+       mutex_init(&bay->lock);
 
        /* Init HW probing */
        if (bay->ops->init)
@@ -700,10 +699,10 @@ static int media_bay_suspend(struct macio_dev *mdev, pm_message_t state)
 
        if (state.event != mdev->ofdev.dev.power.power_state.event
            && (state.event & PM_EVENT_SLEEP)) {
-               down(&bay->lock);
+               mutex_lock(&bay->lock);
                bay->sleeping = 1;
                set_mb_power(bay, 0);
-               up(&bay->lock);
+               mutex_unlock(&bay->lock);
                msleep(MB_POLL_DELAY);
                mdev->ofdev.dev.power.power_state = state;
        }
@@ -722,12 +721,12 @@ static int media_bay_resume(struct macio_dev *mdev)
                   they seem to help the 3400 get it right.
                 */
                /* Force MB power to 0 */
-               down(&bay->lock);
+               mutex_lock(&bay->lock);
                set_mb_power(bay, 0);
                msleep(MB_POWER_DELAY);
                if (bay->ops->content(bay) != bay->content_id) {
                        printk("mediabay%d: content changed during sleep...\n", bay->index);
-                       up(&bay->lock);
+                       mutex_unlock(&bay->lock);
                        return 0;
                }
                set_mb_power(bay, 1);
@@ -743,7 +742,7 @@ static int media_bay_resume(struct macio_dev *mdev)
                } while((bay->state != mb_empty) &&
                        (bay->state != mb_up));
                bay->sleeping = 0;
-               up(&bay->lock);
+               mutex_unlock(&bay->lock);
        }
        return 0;
 }