pcmcia: deprecate CS_BAD_VCC and CS_BAD_VPP
[safe/jmp/linux-2.6] / drivers / pcmcia / yenta_socket.c
index 47e5760..3ecd7c9 100644 (file)
@@ -12,7 +12,6 @@
  */
 #include <linux/init.h>
 #include <linux/pci.h>
-#include <linux/sched.h>
 #include <linux/workqueue.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
@@ -39,17 +38,13 @@ static int pwr_irqs_off;
 module_param(pwr_irqs_off, bool, 0644);
 MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!");
 
-#if 0
-#define debug(x,args...) printk(KERN_DEBUG "%s: " x, __func__ , ##args)
-#else
-#define debug(x,args...)
-#endif
+#define debug(x, s, args...) dev_dbg(&s->dev->dev, x, ##args)
 
 /* Don't ask.. */
 #define to_cycles(ns)  ((ns)/120)
 #define to_ns(cycles)  ((cycles)*120)
 
-/**
+/*
  * yenta PCI irq probing.
  * currently only used in the TI/EnE initialization code
  */
@@ -70,13 +65,13 @@ MODULE_PARM_DESC (override_bios, "yenta ignore bios resource allocation");
 static inline u32 cb_readl(struct yenta_socket *socket, unsigned reg)
 {
        u32 val = readl(socket->base + reg);
-       debug("%p %04x %08x\n", socket, reg, val);
+       debug("%04x %08x\n", socket, reg, val);
        return val;
 }
 
 static inline void cb_writel(struct yenta_socket *socket, unsigned reg, u32 val)
 {
-       debug("%p %04x %08x\n", socket, reg, val);
+       debug("%04x %08x\n", socket, reg, val);
        writel(val, socket->base + reg);
        readl(socket->base + reg); /* avoid problems with PCI write posting */
 }
@@ -85,7 +80,7 @@ static inline u8 config_readb(struct yenta_socket *socket, unsigned offset)
 {
        u8 val;
        pci_read_config_byte(socket->dev, offset, &val);
-       debug("%p %04x %02x\n", socket, offset, val);
+       debug("%04x %02x\n", socket, offset, val);
        return val;
 }
 
@@ -93,7 +88,7 @@ static inline u16 config_readw(struct yenta_socket *socket, unsigned offset)
 {
        u16 val;
        pci_read_config_word(socket->dev, offset, &val);
-       debug("%p %04x %04x\n", socket, offset, val);
+       debug("%04x %04x\n", socket, offset, val);
        return val;
 }
 
@@ -101,32 +96,32 @@ static inline u32 config_readl(struct yenta_socket *socket, unsigned offset)
 {
        u32 val;
        pci_read_config_dword(socket->dev, offset, &val);
-       debug("%p %04x %08x\n", socket, offset, val);
+       debug("%04x %08x\n", socket, offset, val);
        return val;
 }
 
 static inline void config_writeb(struct yenta_socket *socket, unsigned offset, u8 val)
 {
-       debug("%p %04x %02x\n", socket, offset, val);
+       debug("%04x %02x\n", socket, offset, val);
        pci_write_config_byte(socket->dev, offset, val);
 }
 
 static inline void config_writew(struct yenta_socket *socket, unsigned offset, u16 val)
 {
-       debug("%p %04x %04x\n", socket, offset, val);
+       debug("%04x %04x\n", socket, offset, val);
        pci_write_config_word(socket->dev, offset, val);
 }
 
 static inline void config_writel(struct yenta_socket *socket, unsigned offset, u32 val)
 {
-       debug("%p %04x %08x\n", socket, offset, val);
+       debug("%04x %08x\n", socket, offset, val);
        pci_write_config_dword(socket->dev, offset, val);
 }
 
 static inline u8 exca_readb(struct yenta_socket *socket, unsigned reg)
 {
        u8 val = readb(socket->base + 0x800 + reg);
-       debug("%p %04x %02x\n", socket, reg, val);
+       debug("%04x %02x\n", socket, reg, val);
        return val;
 }
 
@@ -135,20 +130,20 @@ static inline u8 exca_readw(struct yenta_socket *socket, unsigned reg)
        u16 val;
        val = readb(socket->base + 0x800 + reg);
        val |= readb(socket->base + 0x800 + reg + 1) << 8;
-       debug("%p %04x %04x\n", socket, reg, val);
+       debug("%04x %04x\n", socket, reg, val);
        return val;
 }
 
 static inline void exca_writeb(struct yenta_socket *socket, unsigned reg, u8 val)
 {
-       debug("%p %04x %02x\n", socket, reg, val);
+       debug("%04x %02x\n", socket, reg, val);
        writeb(val, socket->base + 0x800 + reg);
        readb(socket->base + 0x800 + reg); /* PCI write posting... */
 }
 
 static void exca_writew(struct yenta_socket *socket, unsigned reg, u16 val)
 {
-       debug("%p %04x %04x\n", socket, reg, val);
+       debug("%04x %04x\n", socket, reg, val);
        writeb(val, socket->base + 0x800 + reg);
        writeb(val >> 8, socket->base + 0x800 + reg + 1);
 
@@ -208,7 +203,7 @@ static int yenta_get_status(struct pcmcia_socket *sock, unsigned int *value)
 
 
        if (state & CB_CBCARD) {
-               val |= SS_CARDBUS;      
+               val |= SS_CARDBUS;
                val |= (state & CB_CARDSTS) ? SS_STSCHG : 0;
                val |= (state & (CB_CDETECT1 | CB_CDETECT2)) ? 0 : SS_DETECT;
                val |= (state & CB_PWRCYCLE) ? SS_POWERON | SS_READY : 0;
@@ -442,7 +437,7 @@ static int yenta_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *
 
 
 
-static irqreturn_t yenta_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t yenta_interrupt(int irq, void *dev_id)
 {
        unsigned int events;
        struct yenta_socket *socket = (struct yenta_socket *) dev_id;
@@ -478,7 +473,7 @@ static void yenta_interrupt_wrapper(unsigned long data)
 {
        struct yenta_socket *socket = (struct yenta_socket *) data;
 
-       yenta_interrupt(0, (void *)socket, NULL);
+       yenta_interrupt(0, (void *)socket);
        socket->poll_timer.expires = jiffies + HZ;
        add_timer(&socket->poll_timer);
 }
@@ -651,8 +646,10 @@ static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type
                root = pci_find_parent_resource(socket->dev, res);
                if (root && (request_resource(root, res) == 0))
                        return 0;
-               printk(KERN_INFO "yenta %s: Preassigned resource %d busy or not available, reconfiguring...\n",
-                               pci_name(socket->dev), nr);
+               dev_printk(KERN_INFO, &socket->dev->dev,
+                          "Preassigned resource %d busy or not available, "
+                          "reconfiguring...\n",
+                          nr);
        }
 
        if (type & IORESOURCE_IO) {
@@ -675,8 +672,9 @@ static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type
                        return 1;
        }
 
-       printk(KERN_INFO "yenta %s: no resource of type %x available, trying to continue...\n",
-              pci_name(socket->dev), type);
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "no resource of type %x available, trying to continue...\n",
+                  type);
        res->start = res->end = res->flags = 0;
        return 0;
 }
@@ -889,14 +887,14 @@ static unsigned int yenta_probe_irq(struct yenta_socket *socket, u32 isa_irq_mas
 }
 
 
-/**
+/*
  * yenta PCI irq probing.
  * currently only used in the TI/EnE initialization code
  */
 #ifdef CONFIG_YENTA_TI
 
 /* interrupt handler, only used during probing */
-static irqreturn_t yenta_probe_handler(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t yenta_probe_handler(int irq, void *dev_id)
 {
        struct yenta_socket *socket = (struct yenta_socket *) dev_id;
        u8 csc;
@@ -923,8 +921,9 @@ static int yenta_probe_cb_irq(struct yenta_socket *socket)
 
        socket->probe_status = 0;
 
-       if (request_irq(socket->cb_irq, yenta_probe_handler, SA_SHIRQ, "yenta", socket)) {
-               printk(KERN_WARNING "Yenta: request_irq() in yenta_probe_cb_irq() failed!\n");
+       if (request_irq(socket->cb_irq, yenta_probe_handler, IRQF_SHARED, "yenta", socket)) {
+               dev_printk(KERN_WARNING, &socket->dev->dev,
+                          "request_irq() in yenta_probe_cb_irq() failed!\n");
                return -1;
        }
 
@@ -961,8 +960,9 @@ static void yenta_get_socket_capabilities(struct yenta_socket *socket, u32 isa_i
        else
                socket->socket.irq_mask = 0;
 
-       printk(KERN_INFO "Yenta: ISA IRQ mask 0x%04x, PCI irq %d\n",
-              socket->socket.irq_mask, socket->cb_irq);
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "ISA IRQ mask 0x%04x, PCI irq %d\n",
+                  socket->socket.irq_mask, socket->cb_irq);
 }
 
 /*
@@ -1013,7 +1013,7 @@ static void yenta_config_init(struct yenta_socket *socket)
  * invisible during PCI scans because of a misconfigured subordinate number
  * of the parent brige - some BIOSes seem to be too lazy to set it right.
  * Does the fixup carefully by checking how far it can go without conflicts.
- * See http://bugzilla.kernel.org/show_bug.cgi?id=2944 for more information.
+ * See http\://bugzilla.kernel.org/show_bug.cgi?id=2944 for more information.
  */
 static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge)
 {
@@ -1052,8 +1052,9 @@ static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge)
 
        /* Show that the wanted subordinate number is not possible: */
        if (cardbus_bridge->subordinate > upper_limit)
-               printk(KERN_WARNING "Yenta: Upper limit for fixing this "
-                       "bridge's parent bridge: #%02x\n", upper_limit);
+               dev_printk(KERN_WARNING, &cardbus_bridge->dev,
+                          "Upper limit for fixing this "
+                          "bridge's parent bridge: #%02x\n", upper_limit);
 
        /* If we have room to increase the bridge's subordinate number, */
        if (bridge_to_fix->subordinate < upper_limit) {
@@ -1062,10 +1063,11 @@ static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge)
                unsigned char subordinate_to_assign =
                        min(cardbus_bridge->subordinate, upper_limit);
 
-               printk(KERN_INFO "Yenta: Raising subordinate bus# of parent "
-                       "bus (#%02x) from #%02x to #%02x\n",
-                       bridge_to_fix->number,
-                       bridge_to_fix->subordinate, subordinate_to_assign);
+               dev_printk(KERN_INFO, &bridge_to_fix->dev,
+                          "Raising subordinate bus# of parent "
+                          "bus (#%02x) from #%02x to #%02x\n",
+                          bridge_to_fix->number,
+                          bridge_to_fix->subordinate, subordinate_to_assign);
 
                /* Save the new subordinate in the bus struct of the bridge */
                bridge_to_fix->subordinate = subordinate_to_assign;
@@ -1092,8 +1094,8 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
         * Bail out if so.
         */
        if (!dev->subordinate) {
-               printk(KERN_ERR "Yenta: no bus associated with %s! "
-                       "(try 'pci=assign-busses')\n", pci_name(dev));
+               dev_printk(KERN_ERR, &dev->dev, "no bus associated! "
+                          "(try 'pci=assign-busses')\n");
                return -ENODEV;
        }
 
@@ -1104,7 +1106,7 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
        /* prepare pcmcia_socket */
        socket->socket.ops = &yenta_socket_operations;
        socket->socket.resource_ops = &pccard_nonstatic_ops;
-       socket->socket.dev.dev = &dev->dev;
+       socket->socket.dev.parent = &dev->dev;
        socket->socket.driver_data = socket;
        socket->socket.owner = THIS_MODULE;
        socket->socket.features = SS_CAP_PAGE_REGS | SS_CAP_PCCARD;
@@ -1128,7 +1130,7 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
                goto disable;
 
        if (!pci_resource_start(dev, 0)) {
-               printk(KERN_ERR "No cardbus resource!\n");
+               dev_printk(KERN_ERR, &dev->dev, "No cardbus resource!\n");
                ret = -ENODEV;
                goto release;
        }
@@ -1147,8 +1149,8 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
         * report the subsystem vendor and device for help debugging
         * the irq stuff...
         */
-       printk(KERN_INFO "Yenta: CardBus bridge found at %s [%04x:%04x]\n",
-               pci_name(dev), dev->subsystem_vendor, dev->subsystem_device);
+       dev_printk(KERN_INFO, &dev->dev, "CardBus bridge found [%04x:%04x]\n",
+                  dev->subsystem_vendor, dev->subsystem_device);
 
        yenta_config_init(socket);
 
@@ -1172,7 +1174,7 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
 
        /* We must finish initialization here */
 
-       if (!socket->cb_irq || request_irq(socket->cb_irq, yenta_interrupt, SA_SHIRQ, "yenta", socket)) {
+       if (!socket->cb_irq || request_irq(socket->cb_irq, yenta_interrupt, IRQF_SHARED, "yenta", socket)) {
                /* No IRQ or request_irq failed. Poll */
                socket->cb_irq = 0; /* But zero is a valid IRQ number. */
                init_timer(&socket->poll_timer);
@@ -1180,8 +1182,12 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
                socket->poll_timer.data = (unsigned long)socket;
                socket->poll_timer.expires = jiffies + HZ;
                add_timer(&socket->poll_timer);
-               printk(KERN_INFO "Yenta: no PCI IRQ, CardBus support disabled for this socket.\n"
-                      KERN_INFO "Yenta: check your BIOS CardBus, BIOS IRQ or ACPI settings.\n");
+               dev_printk(KERN_INFO, &dev->dev,
+                          "no PCI IRQ, CardBus support disabled for this "
+                          "socket.\n");
+               dev_printk(KERN_INFO, &dev->dev,
+                          "check your BIOS CardBus, BIOS IRQ or ACPI "
+                          "settings.\n");
        } else {
                socket->socket.features |= SS_CAP_CARDBUS;
        }
@@ -1189,7 +1195,8 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
        /* Figure out what the dang thing can do for the PCMCIA layer... */
        yenta_interrogate(socket);
        yenta_get_socket_capabilities(socket, isa_interrupts);
-       printk(KERN_INFO "Socket status: %08x\n", cb_readl(socket, CB_SOCKET_STATE));
+       dev_printk(KERN_INFO, &dev->dev,
+                  "Socket status: %08x\n", cb_readl(socket, CB_SOCKET_STATE));
 
        yenta_fixup_parent_bridge(dev->subordinate);
 
@@ -1197,8 +1204,12 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
        ret = pcmcia_register_socket(&socket->socket);
        if (ret == 0) {
                /* Add the yenta register attributes */
-               device_create_file(&dev->dev, &dev_attr_yenta_registers);
-               goto out;
+               ret = device_create_file(&dev->dev, &dev_attr_yenta_registers);
+               if (ret == 0)
+                       goto out;
+
+               /* error path... */
+               pcmcia_unregister_socket(&socket->socket);
        }
 
  unmap:
@@ -1213,7 +1224,7 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
        return ret;
 }
 
-
+#ifdef CONFIG_PM
 static int yenta_dev_suspend (struct pci_dev *dev, pm_message_t state)
 {
        struct yenta_socket *socket = pci_get_drvdata(dev);
@@ -1248,12 +1259,18 @@ static int yenta_dev_resume (struct pci_dev *dev)
        struct yenta_socket *socket = pci_get_drvdata(dev);
 
        if (socket) {
+               int rc;
+
                pci_set_power_state(dev, 0);
                /* FIXME: pci_restore_state needs to have a better interface */
                pci_restore_state(dev);
                pci_write_config_dword(dev, 16*4, socket->saved_state[0]);
                pci_write_config_dword(dev, 17*4, socket->saved_state[1]);
-               pci_enable_device(dev);
+
+               rc = pci_enable_device(dev);
+               if (rc)
+                       return rc;
+
                pci_set_master(dev);
 
                if (socket->type && socket->type->restore_state)
@@ -1262,7 +1279,7 @@ static int yenta_dev_resume (struct pci_dev *dev)
 
        return pcmcia_socket_dev_resume(&dev->dev);
 }
-
+#endif
 
 #define CB_ID(vend,dev,type)                           \
        {                                               \
@@ -1359,8 +1376,10 @@ static struct pci_driver yenta_cardbus_driver = {
        .id_table       = yenta_table,
        .probe          = yenta_probe,
        .remove         = __devexit_p(yenta_close),
+#ifdef CONFIG_PM
        .suspend        = yenta_dev_suspend,
        .resume         = yenta_dev_resume,
+#endif
 };