]> err.no Git - linux-2.6/blobdiff - drivers/pnp/manager.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6] / drivers / pnp / manager.c
index 5e43c471909958ab8e4eb4b4645ecf087c22b963..c28caf272c1167f13c761da916af4a0983d878da 100644 (file)
 #include <linux/pnp.h>
 #include <linux/slab.h>
 #include <linux/bitmap.h>
+#include <linux/mutex.h>
 #include "base.h"
 
-DECLARE_MUTEX(pnp_res_mutex);
+DEFINE_MUTEX(pnp_res_mutex);
 
 static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
 {
@@ -22,8 +23,7 @@ static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
        unsigned long *flags;
 
        if (idx >= PNP_MAX_PORT) {
-               pnp_err
-                   ("More than 4 ports is incompatible with pnp specifications.");
+               dev_err(&dev->dev, "too many I/O port resources\n");
                /* pretend we were successful so at least the manager won't try again */
                return 1;
        }
@@ -64,8 +64,7 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
        unsigned long *flags;
 
        if (idx >= PNP_MAX_MEM) {
-               pnp_err
-                   ("More than 8 mems is incompatible with pnp specifications.");
+               dev_err(&dev->dev, "too many memory resources\n");
                /* pretend we were successful so at least the manager won't try again */
                return 1;
        }
@@ -122,8 +121,7 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
        };
 
        if (idx >= PNP_MAX_IRQ) {
-               pnp_err
-                   ("More than 2 irqs is incompatible with pnp specifications.");
+               dev_err(&dev->dev, "too many IRQ resources\n");
                /* pretend we were successful so at least the manager won't try again */
                return 1;
        }
@@ -173,8 +171,7 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
        };
 
        if (idx >= PNP_MAX_DMA) {
-               pnp_err("More than 2 dmas is incompatible with pnp "
-                       "specifications.");
+               dev_err(&dev->dev, "too many DMA resources\n");
                return;
        }
 
@@ -301,7 +298,7 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
        if (!pnp_can_configure(dev))
                return -ENODEV;
 
-       down(&pnp_res_mutex);
+       mutex_lock(&pnp_res_mutex);
        pnp_clean_resource_table(&dev->res);    /* start with a fresh slate */
        if (dev->independent) {
                port = dev->independent->port;
@@ -370,12 +367,12 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
        } else if (dev->dependent)
                goto fail;
 
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
        return 1;
 
 fail:
        pnp_clean_resource_table(&dev->res);
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
        return 0;
 }
 
@@ -400,7 +397,7 @@ int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
                return -ENOMEM;
        *bak = dev->res;
 
-       down(&pnp_res_mutex);
+       mutex_lock(&pnp_res_mutex);
        dev->res = *res;
        if (!(mode & PNP_CONFIG_FORCE)) {
                for (i = 0; i < PNP_MAX_PORT; i++) {
@@ -420,14 +417,14 @@ int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
                                goto fail;
                }
        }
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
 
        kfree(bak);
        return 0;
 
 fail:
        dev->res = *bak;
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
        kfree(bak);
        return -EINVAL;
 }
@@ -442,8 +439,7 @@ int pnp_auto_config_dev(struct pnp_dev *dev)
        int i = 1;
 
        if (!pnp_can_configure(dev)) {
-               pnp_dbg("Device %s does not support resource configuration.",
-                       dev->dev.bus_id);
+               dev_dbg(&dev->dev, "configuration not supported\n");
                return -ENODEV;
        }
 
@@ -460,7 +456,7 @@ int pnp_auto_config_dev(struct pnp_dev *dev)
                } while (dep);
        }
 
-       pnp_err("Unable to assign resources to device %s.", dev->dev.bus_id);
+       dev_err(&dev->dev, "unable to assign resources\n");
        return -EBUSY;
 }
 
@@ -473,17 +469,16 @@ int pnp_auto_config_dev(struct pnp_dev *dev)
 int pnp_start_dev(struct pnp_dev *dev)
 {
        if (!pnp_can_write(dev)) {
-               pnp_dbg("Device %s does not support activation.",
-                       dev->dev.bus_id);
+               dev_dbg(&dev->dev, "activation not supported\n");
                return -EINVAL;
        }
 
        if (dev->protocol->set(dev, &dev->res) < 0) {
-               pnp_err("Failed to activate device %s.", dev->dev.bus_id);
+               dev_err(&dev->dev, "activation failed\n");
                return -EIO;
        }
 
-       pnp_info("Device %s activated.", dev->dev.bus_id);
+       dev_info(&dev->dev, "activated\n");
        return 0;
 }
 
@@ -496,16 +491,15 @@ int pnp_start_dev(struct pnp_dev *dev)
 int pnp_stop_dev(struct pnp_dev *dev)
 {
        if (!pnp_can_disable(dev)) {
-               pnp_dbg("Device %s does not support disabling.",
-                       dev->dev.bus_id);
+               dev_dbg(&dev->dev, "disabling not supported\n");
                return -EINVAL;
        }
        if (dev->protocol->disable(dev) < 0) {
-               pnp_err("Failed to disable device %s.", dev->dev.bus_id);
+               dev_err(&dev->dev, "disable failed\n");
                return -EIO;
        }
 
-       pnp_info("Device %s disabled.", dev->dev.bus_id);
+       dev_info(&dev->dev, "disabled\n");
        return 0;
 }
 
@@ -520,7 +514,7 @@ int pnp_activate_dev(struct pnp_dev *dev)
        int error;
 
        if (dev->active)
-               return 0;       /* the device is already active */
+               return 0;
 
        /* ensure resources are allocated */
        if (pnp_auto_config_dev(dev))
@@ -531,7 +525,7 @@ int pnp_activate_dev(struct pnp_dev *dev)
                return error;
 
        dev->active = 1;
-       return 1;
+       return 0;
 }
 
 /**
@@ -545,7 +539,7 @@ int pnp_disable_dev(struct pnp_dev *dev)
        int error;
 
        if (!dev->active)
-               return 0;       /* the device is already disabled */
+               return 0;
 
        error = pnp_stop_dev(dev);
        if (error)
@@ -554,11 +548,11 @@ int pnp_disable_dev(struct pnp_dev *dev)
        dev->active = 0;
 
        /* release the resources so that other devices can use them */
-       down(&pnp_res_mutex);
+       mutex_lock(&pnp_res_mutex);
        pnp_clean_resource_table(&dev->res);
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
 
-       return 1;
+       return 0;
 }
 
 /**