Browse Source

PNP: add pnp_get_resource() interface

This adds a pnp_get_resource() that works the same way as
platform_get_resource().  This will enable us to consolidate
many pnp_resource_table references in one place, which will
make it easier to make the table dynamic.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Bjorn Helgaas 17 years ago
parent
commit
b90eca0a61
2 changed files with 28 additions and 0 deletions
  1. 27 0
      drivers/pnp/resource.c
  2. 1 0
      include/linux/pnp.h

+ 27 - 0
drivers/pnp/resource.c

@@ -487,6 +487,33 @@ int pnp_check_dma(struct pnp_dev *dev, int idx)
 #endif
 #endif
 }
 }
 
 
+struct resource *pnp_get_resource(struct pnp_dev *dev,
+				  unsigned int type, unsigned int num)
+{
+	struct pnp_resource_table *res = &dev->res;
+
+	switch (type) {
+	case IORESOURCE_IO:
+		if (num >= PNP_MAX_PORT)
+			return NULL;
+		return &res->port_resource[num];
+	case IORESOURCE_MEM:
+		if (num >= PNP_MAX_MEM)
+			return NULL;
+		return &res->mem_resource[num];
+	case IORESOURCE_IRQ:
+		if (num >= PNP_MAX_IRQ)
+			return NULL;
+		return &res->irq_resource[num];
+	case IORESOURCE_DMA:
+		if (num >= PNP_MAX_DMA)
+			return NULL;
+		return &res->dma_resource[num];
+	}
+	return NULL;
+}
+EXPORT_SYMBOL(pnp_get_resource);
+
 /* format is: pnp_reserve_irq=irq1[,irq2] .... */
 /* format is: pnp_reserve_irq=irq1[,irq2] .... */
 static int __init pnp_setup_reserve_irq(char *str)
 static int __init pnp_setup_reserve_irq(char *str)
 {
 {

+ 1 - 0
include/linux/pnp.h

@@ -25,6 +25,7 @@ struct pnp_dev;
 /*
 /*
  * Resource Management
  * Resource Management
  */
  */
+struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int);
 
 
 /* Use these instead of directly reading pnp_dev to get resource information */
 /* Use these instead of directly reading pnp_dev to get resource information */
 #define pnp_port_start(dev,bar)   ((dev)->res.port_resource[(bar)].start)
 #define pnp_port_start(dev,bar)   ((dev)->res.port_resource[(bar)].start)