sony-laptop: newline-terminate the printk for backlight change failure
[linux-2.6.git] / drivers / misc / tifm_7xx1.c
index 3563869..67503ea 100644 (file)
@@ -11,7 +11,6 @@
 
 #include <linux/tifm.h>
 #include <linux/dma-mapping.h>
-#include <linux/freezer.h>
 
 #define DRIVER_NAME "tifm_7xx1"
 #define DRIVER_VERSION "0.8"
@@ -41,8 +40,7 @@ static irqreturn_t tifm_7xx1_isr(int irq, void *dev_id)
 {
        struct tifm_adapter *fm = dev_id;
        struct tifm_dev *sock;
-       unsigned int irq_status;
-       unsigned int cnt;
+       unsigned int irq_status, cnt;
 
        spin_lock(&fm->lock);
        irq_status = readl(fm->addr + FM_INTERRUPT_STATUS);
@@ -107,7 +105,8 @@ static unsigned char tifm_7xx1_toggle_sock_power(char __iomem *sock_addr)
            == TIFM_TYPE_XD)
                msleep(40);
 
-       writel((s_state & 7) | 0x0c00, sock_addr + SOCK_CONTROL);
+       writel((s_state & TIFM_CTRL_POWER_MASK) | 0x0c00,
+              sock_addr + SOCK_CONTROL);
        /* wait for power to stabilize */
        msleep(20);
        for (cnt = 16; cnt <= 256; cnt <<= 1) {
@@ -124,6 +123,12 @@ static unsigned char tifm_7xx1_toggle_sock_power(char __iomem *sock_addr)
        return (readl(sock_addr + SOCK_PRESENT_STATE) >> 4) & 7;
 }
 
+inline static void tifm_7xx1_sock_power_off(char __iomem *sock_addr)
+{
+       writel((~TIFM_CTRL_POWER_MASK) & readl(sock_addr + SOCK_CONTROL),
+              sock_addr + SOCK_CONTROL);
+}
+
 inline static char __iomem *
 tifm_7xx1_sock_addr(char __iomem *base_addr, unsigned int sock_num)
 {
@@ -134,17 +139,17 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
 {
        struct tifm_adapter *fm = container_of(work, struct tifm_adapter,
                                               media_switcher);
+       struct tifm_dev *sock;
+       char __iomem *sock_addr;
        unsigned long flags;
        unsigned char media_id;
-       int cnt;
-       struct tifm_dev *sock;
-       unsigned int socket_change_set;
+       unsigned int socket_change_set, cnt;
 
        spin_lock_irqsave(&fm->lock, flags);
        socket_change_set = fm->socket_change_set;
        fm->socket_change_set = 0;
 
-       dev_dbg(fm->cdev.dev, "checking media set %x\n",
+       dev_dbg(fm->dev.parent, "checking media set %x\n",
                socket_change_set);
 
        if (!socket_change_set) {
@@ -159,13 +164,14 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
                if (sock) {
                        printk(KERN_INFO
                               "%s : demand removing card from socket %u:%u\n",
-                              fm->cdev.class_id, fm->id, cnt);
+                              fm->dev.bus_id, fm->id, cnt);
                        fm->sockets[cnt] = NULL;
+                       sock_addr = sock->addr;
                        spin_unlock_irqrestore(&fm->lock, flags);
                        device_unregister(&sock->dev);
                        spin_lock_irqsave(&fm->lock, flags);
-                       writel(0x0e00, tifm_7xx1_sock_addr(fm->addr, cnt)
-                              + SOCK_CONTROL);
+                       tifm_7xx1_sock_power_off(sock_addr);
+                       writel(0x0e00, sock_addr + SOCK_CONTROL);
                }
 
                spin_unlock_irqrestore(&fm->lock, flags);
@@ -208,8 +214,16 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
 
 static int tifm_7xx1_suspend(struct pci_dev *dev, pm_message_t state)
 {
+       struct tifm_adapter *fm = pci_get_drvdata(dev);
+       int cnt;
+
        dev_dbg(&dev->dev, "suspending host\n");
 
+       for (cnt = 0; cnt < fm->num_sockets; cnt++) {
+               if (fm->sockets[cnt])
+                       tifm_7xx1_sock_power_off(fm->sockets[cnt]->addr);
+       }
+
        pci_save_state(dev);
        pci_enable_wake(dev, pci_choose_state(dev, state), 0);
        pci_disable_device(dev);
@@ -220,7 +234,8 @@ static int tifm_7xx1_suspend(struct pci_dev *dev, pm_message_t state)
 static int tifm_7xx1_resume(struct pci_dev *dev)
 {
        struct tifm_adapter *fm = pci_get_drvdata(dev);
-       int cnt, rc;
+       int rc;
+       unsigned int good_sockets = 0, bad_sockets = 0;
        unsigned long flags;
        unsigned char new_ids[fm->num_sockets];
        DECLARE_COMPLETION_ONSTACK(finish_resume);
@@ -234,46 +249,49 @@ static int tifm_7xx1_resume(struct pci_dev *dev)
 
        dev_dbg(&dev->dev, "resuming host\n");
 
-       for (cnt = 0; cnt < fm->num_sockets; cnt++)
-               new_ids[cnt] = tifm_7xx1_toggle_sock_power(
-                                       tifm_7xx1_sock_addr(fm->addr, cnt));
+       for (rc = 0; rc < fm->num_sockets; rc++)
+               new_ids[rc] = tifm_7xx1_toggle_sock_power(
+                                       tifm_7xx1_sock_addr(fm->addr, rc));
        spin_lock_irqsave(&fm->lock, flags);
-       fm->socket_change_set = 0;
-       for (cnt = 0; cnt < fm->num_sockets; cnt++) {
-               if (fm->sockets[cnt]) {
-                       if (fm->sockets[cnt]->type == new_ids[cnt])
-                               fm->socket_change_set |= 1 << cnt;
-
-                       fm->sockets[cnt]->type = new_ids[cnt];
+       for (rc = 0; rc < fm->num_sockets; rc++) {
+               if (fm->sockets[rc]) {
+                       if (fm->sockets[rc]->type == new_ids[rc])
+                               good_sockets |= 1 << rc;
+                       else
+                               bad_sockets |= 1 << rc;
                }
        }
 
        writel(TIFM_IRQ_ENABLE | TIFM_IRQ_SOCKMASK((1 << fm->num_sockets) - 1),
               fm->addr + FM_SET_INTERRUPT_ENABLE);
-       if (!fm->socket_change_set) {
-               spin_unlock_irqrestore(&fm->lock, flags);
-               return 0;
-       } else {
-               fm->socket_change_set = 0;
+       dev_dbg(&dev->dev, "change sets on resume: good %x, bad %x\n",
+               good_sockets, bad_sockets);
+
+       fm->socket_change_set = 0;
+       if (good_sockets) {
                fm->finish_me = &finish_resume;
                spin_unlock_irqrestore(&fm->lock, flags);
+               rc = wait_for_completion_timeout(&finish_resume, HZ);
+               dev_dbg(&dev->dev, "wait returned %d\n", rc);
+               writel(TIFM_IRQ_FIFOMASK(good_sockets)
+                      | TIFM_IRQ_CARDMASK(good_sockets),
+                      fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
+               writel(TIFM_IRQ_FIFOMASK(good_sockets)
+                      | TIFM_IRQ_CARDMASK(good_sockets),
+                      fm->addr + FM_SET_INTERRUPT_ENABLE);
+               spin_lock_irqsave(&fm->lock, flags);
+               fm->finish_me = NULL;
+               fm->socket_change_set ^= good_sockets & fm->socket_change_set;
        }
 
-       wait_for_completion_timeout(&finish_resume, HZ);
+       fm->socket_change_set |= bad_sockets;
+       if (fm->socket_change_set)
+               tifm_queue_work(&fm->media_switcher);
 
-       spin_lock_irqsave(&fm->lock, flags);
-       fm->finish_me = NULL;
-       writel(TIFM_IRQ_FIFOMASK(fm->socket_change_set)
-              | TIFM_IRQ_CARDMASK(fm->socket_change_set),
-              fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
-       writel(TIFM_IRQ_FIFOMASK(fm->socket_change_set)
-              | TIFM_IRQ_CARDMASK(fm->socket_change_set),
-              fm->addr + FM_SET_INTERRUPT_ENABLE);
+       spin_unlock_irqrestore(&fm->lock, flags);
        writel(TIFM_IRQ_ENABLE,
               fm->addr + FM_SET_INTERRUPT_ENABLE);
-       fm->socket_change_set = 0;
 
-       spin_unlock_irqrestore(&fm->lock, flags);
        return 0;
 }
 
@@ -284,6 +302,21 @@ static int tifm_7xx1_resume(struct pci_dev *dev)
 
 #endif /* CONFIG_PM */
 
+static int tifm_7xx1_dummy_has_ms_pif(struct tifm_adapter *fm,
+                                     struct tifm_dev *sock)
+{
+       return 0;
+}
+
+static int tifm_7xx1_has_ms_pif(struct tifm_adapter *fm, struct tifm_dev *sock)
+{
+       if (((fm->num_sockets == 4) && (sock->socket_id == 2))
+           || ((fm->num_sockets == 2) && (sock->socket_id == 0)))
+               return 1;
+
+       return 0;
+}
+
 static int tifm_7xx1_probe(struct pci_dev *dev,
                           const struct pci_device_id *dev_id)
 {
@@ -318,6 +351,7 @@ static int tifm_7xx1_probe(struct pci_dev *dev,
 
        INIT_WORK(&fm->media_switcher, tifm_7xx1_switch_media);
        fm->eject = tifm_7xx1_eject;
+       fm->has_ms_pif = tifm_7xx1_has_ms_pif;
        pci_set_drvdata(dev, fm);
 
        fm->addr = ioremap(pci_resource_start(dev, 0),
@@ -325,7 +359,7 @@ static int tifm_7xx1_probe(struct pci_dev *dev,
        if (!fm->addr)
                goto err_out_free;
 
-       rc = request_irq(dev->irq, tifm_7xx1_isr, SA_SHIRQ, DRIVER_NAME, fm);
+       rc = request_irq(dev->irq, tifm_7xx1_isr, IRQF_SHARED, DRIVER_NAME, fm);
        if (rc)
                goto err_out_unmap;
 
@@ -334,6 +368,8 @@ static int tifm_7xx1_probe(struct pci_dev *dev,
                goto err_out_irq;
 
        writel(TIFM_IRQ_ENABLE | TIFM_IRQ_SOCKMASK((1 << fm->num_sockets) - 1),
+              fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
+       writel(TIFM_IRQ_ENABLE | TIFM_IRQ_SOCKMASK((1 << fm->num_sockets) - 1),
               fm->addr + FM_SET_INTERRUPT_ENABLE);
        return 0;
 
@@ -356,14 +392,19 @@ err_out:
 static void tifm_7xx1_remove(struct pci_dev *dev)
 {
        struct tifm_adapter *fm = pci_get_drvdata(dev);
+       int cnt;
 
        fm->eject = tifm_7xx1_dummy_eject;
+       fm->has_ms_pif = tifm_7xx1_dummy_has_ms_pif;
        writel(TIFM_IRQ_SETALL, fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
        mmiowb();
        free_irq(dev->irq, fm);
 
        tifm_remove_adapter(fm);
 
+       for (cnt = 0; cnt < fm->num_sockets; cnt++)
+               tifm_7xx1_sock_power_off(tifm_7xx1_sock_addr(fm->addr, cnt));
+
        pci_set_drvdata(dev, NULL);
 
        iounmap(fm->addr);