]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/pnp/interface.c
PNP: convert assign, interface to use pnp_get_resource(), not pnp_resource_table
[linux-2.6-omap-h63xx.git] / drivers / pnp / interface.c
index a0cfb75bbb8d72e82fbf74cfbd992ddce08f5245..a608054a3e5304ae9e7d00fd0a72c6369edd8c25 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * interface.c - contains everything related to the user interface
  *
- * Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@suse.cz>
+ * Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@perex.cz>
  * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
  */
 
 #include <linux/errno.h>
 #include <linux/list.h>
 #include <linux/types.h>
+#include <linux/pnp.h>
 #include <linux/stat.h>
 #include <linux/ctype.h>
 #include <linux/slab.h>
+#include <linux/mutex.h>
+
 #include <asm/uaccess.h>
 
 #include "base.h"
@@ -315,20 +318,18 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
        return ret;
 }
 
-extern struct semaphore pnp_res_mutex;
-
 static ssize_t
 pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                          const char *ubuf, size_t count)
 {
        struct pnp_dev *dev = to_pnp_dev(dmdev);
+       struct resource *res;
        char *buf = (void *)ubuf;
        int retval = 0;
 
        if (dev->status & PNP_ATTACHED) {
                retval = -EBUSY;
-               pnp_info("Device %s cannot be configured because it is in use.",
-                        dev->dev.bus_id);
+               dev_info(&dev->dev, "in use; can't configure\n");
                goto done;
        }
 
@@ -351,21 +352,21 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
        if (!strnicmp(buf, "auto", 4)) {
                if (dev->active)
                        goto done;
-               pnp_init_resource_table(&dev->res);
+               pnp_init_resources(dev);
                retval = pnp_auto_config_dev(dev);
                goto done;
        }
        if (!strnicmp(buf, "clear", 5)) {
                if (dev->active)
                        goto done;
-               pnp_init_resource_table(&dev->res);
+               pnp_init_resources(dev);
                goto done;
        }
        if (!strnicmp(buf, "get", 3)) {
-               down(&pnp_res_mutex);
+               mutex_lock(&pnp_res_mutex);
                if (pnp_can_read(dev))
-                       dev->protocol->get(dev, &dev->res);
-               up(&pnp_res_mutex);
+                       dev->protocol->get(dev);
+               mutex_unlock(&pnp_res_mutex);
                goto done;
        }
        if (!strnicmp(buf, "set", 3)) {
@@ -373,8 +374,8 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                if (dev->active)
                        goto done;
                buf += 3;
-               pnp_init_resource_table(&dev->res);
-               down(&pnp_res_mutex);
+               pnp_init_resources(dev);
+               mutex_lock(&pnp_res_mutex);
                while (1) {
                        while (isspace(*buf))
                                ++buf;
@@ -382,81 +383,77 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                                buf += 2;
                                while (isspace(*buf))
                                        ++buf;
-                               dev->res.port_resource[nport].start =
-                                   simple_strtoul(buf, &buf, 0);
+                               res = pnp_get_resource(dev, IORESOURCE_IO,
+                                                      nport);
+                               if (!res)
+                                       break;
+                               res->start = simple_strtoul(buf, &buf, 0);
                                while (isspace(*buf))
                                        ++buf;
                                if (*buf == '-') {
                                        buf += 1;
                                        while (isspace(*buf))
                                                ++buf;
-                                       dev->res.port_resource[nport].end =
-                                           simple_strtoul(buf, &buf, 0);
+                                       res->end = simple_strtoul(buf, &buf, 0);
                                } else
-                                       dev->res.port_resource[nport].end =
-                                           dev->res.port_resource[nport].start;
-                               dev->res.port_resource[nport].flags =
-                                   IORESOURCE_IO;
+                                       res->end = res->start;
+                               res->flags = IORESOURCE_IO;
                                nport++;
-                               if (nport >= PNP_MAX_PORT)
-                                       break;
                                continue;
                        }
                        if (!strnicmp(buf, "mem", 3)) {
                                buf += 3;
                                while (isspace(*buf))
                                        ++buf;
-                               dev->res.mem_resource[nmem].start =
-                                   simple_strtoul(buf, &buf, 0);
+                               res = pnp_get_resource(dev, IORESOURCE_MEM,
+                                                      nmem);
+                               if (!res)
+                                       break;
+                               res->start = simple_strtoul(buf, &buf, 0);
                                while (isspace(*buf))
                                        ++buf;
                                if (*buf == '-') {
                                        buf += 1;
                                        while (isspace(*buf))
                                                ++buf;
-                                       dev->res.mem_resource[nmem].end =
-                                           simple_strtoul(buf, &buf, 0);
+                                       res->end = simple_strtoul(buf, &buf, 0);
                                } else
-                                       dev->res.mem_resource[nmem].end =
-                                           dev->res.mem_resource[nmem].start;
-                               dev->res.mem_resource[nmem].flags =
-                                   IORESOURCE_MEM;
+                                       res->end = res->start;
+                               res->flags = IORESOURCE_MEM;
                                nmem++;
-                               if (nmem >= PNP_MAX_MEM)
-                                       break;
                                continue;
                        }
                        if (!strnicmp(buf, "irq", 3)) {
                                buf += 3;
                                while (isspace(*buf))
                                        ++buf;
-                               dev->res.irq_resource[nirq].start =
-                                   dev->res.irq_resource[nirq].end =
+                               res = pnp_get_resource(dev, IORESOURCE_IRQ,
+                                                      nirq);
+                               if (!res)
+                                       break;
+                               res->start = res->end =
                                    simple_strtoul(buf, &buf, 0);
-                               dev->res.irq_resource[nirq].flags =
-                                   IORESOURCE_IRQ;
+                               res->flags = IORESOURCE_IRQ;
                                nirq++;
-                               if (nirq >= PNP_MAX_IRQ)
-                                       break;
                                continue;
                        }
                        if (!strnicmp(buf, "dma", 3)) {
                                buf += 3;
                                while (isspace(*buf))
                                        ++buf;
-                               dev->res.dma_resource[ndma].start =
-                                   dev->res.dma_resource[ndma].end =
+                               res = pnp_get_resource(dev, IORESOURCE_DMA,
+                                                      ndma);
+                               if (!res)
+                                       break;
+                               res->start = res->end =
                                    simple_strtoul(buf, &buf, 0);
-                               dev->res.dma_resource[ndma].flags =
-                                   IORESOURCE_DMA;
+                               res->flags = IORESOURCE_DMA;
                                ndma++;
-                               if (ndma >= PNP_MAX_DMA)
-                                       break;
                                continue;
                        }
                        break;
                }
-               up(&pnp_res_mutex);
+               mutex_unlock(&pnp_res_mutex);
                goto done;
        }