printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / devices / pnp_device.c
index fadab855894e7d33308e89e0a18669de57b0e5f0..721d1ce3dcef6dcc76d53ee5e727f899ebfee37a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the LinuxBIOS project.
+ * This file is part of the coreboot project.
  *
  * Copyright (C) 2004 Linux Networx
  * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
 
 void pnp_write_config(device_t dev, uint8_t reg, uint8_t value)
 {
-       outb(reg, dev->path.u.pnp.port);
-       outb(value, dev->path.u.pnp.port + 1);
+       outb(reg, dev->path.pnp.port);
+       outb(value, dev->path.pnp.port + 1);
 }
 
 uint8_t pnp_read_config(device_t dev, uint8_t reg)
 {
-       outb(reg, dev->path.u.pnp.port);
-       return inb(dev->path.u.pnp.port + 1);
+       outb(reg, dev->path.pnp.port);
+       return inb(dev->path.pnp.port + 1);
 }
 
 void pnp_set_logical_device(device_t dev)
 {
-       pnp_write_config(dev, 0x07, dev->path.u.pnp.device);
+       pnp_write_config(dev, 0x07, dev->path.pnp.device & 0xff);
 }
 
 void pnp_set_enable(device_t dev, int enable)
 {
-       pnp_write_config(dev, 0x30, enable?0x1:0x0);
+       uint8_t tmp, bitpos;
+
+       tmp = pnp_read_config(dev, 0x30);
+       /* handle the virtual devices, which share same LDN register */
+       bitpos = (dev->path.pnp.device >> 8) & 0x7;
+
+       if (enable) {
+               tmp |= (1 << bitpos);
+       } else {
+               tmp &= ~(1 << bitpos);
+       }
+       pnp_write_config(dev, 0x30, tmp);
 }
 
 int pnp_read_enable(device_t dev)
 {
-       return !!pnp_read_config(dev, 0x30);
+       uint8_t tmp, bitpos;
+       tmp = pnp_read_config(dev, 0x30);
+       /* handle the virtual devices, which share same LDN register */
+       bitpos = (dev->path.pnp.device >> 8) & 0x7;
+       return !!(tmp & (1 << bitpos));
 }
 
 void pnp_set_iobase(device_t dev, unsigned index, unsigned iobase)
@@ -88,7 +103,7 @@ void pnp_read_resources(device_t dev)
 static void pnp_set_resource(device_t dev, struct resource *resource)
 {
        if (!(resource->flags & IORESOURCE_ASSIGNED)) {
-               printk_err("ERROR: %s %02x %s size: 0x%010Lx not assigned\n",
+               printk(BIOS_ERR, "ERROR: %s %02lx %s size: 0x%010Lx not assigned\n",
                        dev_path(dev), resource->index,
                        resource_type(resource),
                        resource->size);
@@ -106,7 +121,7 @@ static void pnp_set_resource(device_t dev, struct resource *resource)
                pnp_set_irq(dev, resource->index, resource->base);
        }
        else {
-               printk_err("ERROR: %s %02x unknown resource type\n",
+               printk(BIOS_ERR, "ERROR: %s %02lx unknown resource type\n",
                        dev_path(dev), resource->index);
                return;
        }
@@ -225,7 +240,25 @@ static void get_resources(device_t dev, struct pnp_info *info)
                resource = new_resource(dev, PNP_IDX_DRQ1);
                resource->size = 1;
                resource->flags |= IORESOURCE_DRQ;
-       }       
+       }
+       /* These are not IRQs, but set the flag to have the
+        * resource allocator do the right thing
+        */
+       if (info->flags & PNP_EN) {
+               resource = new_resource(dev, PNP_IDX_EN);
+               resource->size = 1;
+               resource->flags |= IORESOURCE_IRQ;
+       }
+       if (info->flags & PNP_MSC0) {
+               resource = new_resource(dev, PNP_IDX_MSC0);
+               resource->size = 1;
+               resource->flags |= IORESOURCE_IRQ;
+       }
+       if (info->flags & PNP_MSC1) {
+               resource = new_resource(dev, PNP_IDX_MSC1);
+               resource->size = 1;
+               resource->flags |= IORESOURCE_IRQ;
+       }
 } 
 
 void pnp_enable_devices(device_t base_dev, struct device_operations *ops, 
@@ -236,11 +269,15 @@ void pnp_enable_devices(device_t base_dev, struct device_operations *ops,
        int i;
 
        path.type       = DEVICE_PATH_PNP;
-       path.u.pnp.port = base_dev->path.u.pnp.port;
+       path.pnp.port = base_dev->path.pnp.port;
        
        /* Setup the ops and resources on the newly allocated devices */
        for(i = 0; i < functions; i++) {
-               path.u.pnp.device = info[i].function;
+               /* Skip logical devices this Super I/O doesn't have. */
+               if (info[i].function == -1)
+                       continue;
+
+               path.pnp.device = info[i].function;
                dev = alloc_find_dev(base_dev->bus, &path);
                
                /* Don't initialize a device multiple times */