]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/net/wireless/libertas/if_sdio.c
libertas: fix 8686 firmware loading regression
[net-next-2.6.git] / drivers / net / wireless / libertas / if_sdio.c
index 7a73f625273ba7730aac480e377a85df64161aa5..094176e92ebe6f5ecda038e9e6f22ef1824c787a 100644 (file)
@@ -34,6 +34,8 @@
 #include <linux/mmc/card.h>
 #include <linux/mmc/sdio_func.h>
 #include <linux/mmc/sdio_ids.h>
+#include <linux/mmc/sdio.h>
+#include <linux/mmc/host.h>
 
 #include "host.h"
 #include "decl.h"
@@ -312,12 +314,30 @@ out:
        return ret;
 }
 
+static int if_sdio_wait_status(struct if_sdio_card *card, const u8 condition)
+{
+       u8 status;
+       unsigned long timeout;
+       int ret = 0;
+
+       timeout = jiffies + HZ;
+       while (1) {
+               status = sdio_readb(card->func, IF_SDIO_STATUS, &ret);
+               if (ret)
+                       return ret;
+               if ((status & condition) == condition)
+                       break;
+               if (time_after(jiffies, timeout))
+                       return -ETIMEDOUT;
+               mdelay(1);
+       }
+       return ret;
+}
+
 static int if_sdio_card_to_host(struct if_sdio_card *card)
 {
        int ret;
-       u8 status;
        u16 size, type, chunk;
-       unsigned long timeout;
 
        lbs_deb_enter(LBS_DEB_SDIO);
 
@@ -332,19 +352,9 @@ static int if_sdio_card_to_host(struct if_sdio_card *card)
                goto out;
        }
 
-       timeout = jiffies + HZ;
-       while (1) {
-               status = sdio_readb(card->func, IF_SDIO_STATUS, &ret);
-               if (ret)
-                       goto out;
-               if (status & IF_SDIO_IO_RDY)
-                       break;
-               if (time_after(jiffies, timeout)) {
-                       ret = -ETIMEDOUT;
-                       goto out;
-               }
-               mdelay(1);
-       }
+       ret = if_sdio_wait_status(card, IF_SDIO_IO_RDY);
+       if (ret)
+               goto out;
 
        /*
         * The transfer must be in one transaction or the firmware
@@ -411,8 +421,6 @@ static void if_sdio_host_to_card_worker(struct work_struct *work)
 {
        struct if_sdio_card *card;
        struct if_sdio_packet *packet;
-       unsigned long timeout;
-       u8 status;
        int ret;
        unsigned long flags;
 
@@ -432,25 +440,15 @@ static void if_sdio_host_to_card_worker(struct work_struct *work)
 
                sdio_claim_host(card->func);
 
-               timeout = jiffies + HZ;
-               while (1) {
-                       status = sdio_readb(card->func, IF_SDIO_STATUS, &ret);
-                       if (ret)
-                               goto release;
-                       if (status & IF_SDIO_IO_RDY)
-                               break;
-                       if (time_after(jiffies, timeout)) {
-                               ret = -ETIMEDOUT;
-                               goto release;
-                       }
-                       mdelay(1);
+               ret = if_sdio_wait_status(card, IF_SDIO_IO_RDY);
+               if (ret == 0) {
+                       ret = sdio_writesb(card->func, card->ioport,
+                                          packet->buffer, packet->nb);
                }
 
-               ret = sdio_writesb(card->func, card->ioport,
-                               packet->buffer, packet->nb);
                if (ret)
-                       goto release;
-release:
+                       lbs_pr_err("error %d sending packet to firmware\n", ret);
+
                sdio_release_host(card->func);
 
                kfree(packet);
@@ -463,10 +461,11 @@ release:
 /* Firmware                                                         */
 /********************************************************************/
 
+#define FW_DL_READY_STATUS (IF_SDIO_IO_RDY | IF_SDIO_DL_RDY)
+
 static int if_sdio_prog_helper(struct if_sdio_card *card)
 {
        int ret;
-       u8 status;
        const struct firmware *fw;
        unsigned long timeout;
        u8 *chunk_buffer;
@@ -498,20 +497,14 @@ static int if_sdio_prog_helper(struct if_sdio_card *card)
        size = fw->size;
 
        while (size) {
-               timeout = jiffies + HZ;
-               while (1) {
-                       status = sdio_readb(card->func, IF_SDIO_STATUS, &ret);
-                       if (ret)
-                               goto release;
-                       if ((status & IF_SDIO_IO_RDY) &&
-                                       (status & IF_SDIO_DL_RDY))
-                               break;
-                       if (time_after(jiffies, timeout)) {
-                               ret = -ETIMEDOUT;
-                               goto release;
-                       }
-                       mdelay(1);
-               }
+               ret = if_sdio_wait_status(card, FW_DL_READY_STATUS);
+               if (ret)
+                       goto release;
+
+               /* On some platforms (like Davinci) the chip needs more time
+                * between helper blocks.
+                */
+               mdelay(2);
 
                chunk_size = min(size, (size_t)60);
 
@@ -581,7 +574,6 @@ out:
 static int if_sdio_prog_real(struct if_sdio_card *card)
 {
        int ret;
-       u8 status;
        const struct firmware *fw;
        unsigned long timeout;
        u8 *chunk_buffer;
@@ -613,20 +605,9 @@ static int if_sdio_prog_real(struct if_sdio_card *card)
        size = fw->size;
 
        while (size) {
-               timeout = jiffies + HZ;
-               while (1) {
-                       status = sdio_readb(card->func, IF_SDIO_STATUS, &ret);
-                       if (ret)
-                               goto release;
-                       if ((status & IF_SDIO_IO_RDY) &&
-                                       (status & IF_SDIO_DL_RDY))
-                               break;
-                       if (time_after(jiffies, timeout)) {
-                               ret = -ETIMEDOUT;
-                               goto release;
-                       }
-                       mdelay(1);
-               }
+               ret = if_sdio_wait_status(card, FW_DL_READY_STATUS);
+               if (ret)
+                       goto release;
 
                req_size = sdio_readb(card->func, IF_SDIO_RD_BASE, &ret);
                if (ret)
@@ -942,6 +923,7 @@ static int if_sdio_probe(struct sdio_func *func,
        int ret, i;
        unsigned int model;
        struct if_sdio_packet *packet;
+       struct mmc_host *host = func->card->host;
 
        lbs_deb_enter(LBS_DEB_SDIO);
 
@@ -1022,6 +1004,25 @@ static int if_sdio_probe(struct sdio_func *func,
        if (ret)
                goto disable;
 
+       /* For 1-bit transfers to the 8686 model, we need to enable the
+        * interrupt flag in the CCCR register. Set the MMC_QUIRK_LENIENT_FN0
+        * bit to allow access to non-vendor registers. */
+       if ((card->model == IF_SDIO_MODEL_8686) &&
+           (host->caps & MMC_CAP_SDIO_IRQ) &&
+           (host->ios.bus_width == MMC_BUS_WIDTH_1)) {
+               u8 reg;
+
+               func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
+               reg = sdio_f0_readb(func, SDIO_CCCR_IF, &ret);
+               if (ret)
+                       goto release_int;
+
+               reg |= SDIO_BUS_ECSI;
+               sdio_f0_writeb(func, reg, SDIO_CCCR_IF, &ret);
+               if (ret)
+                       goto release_int;
+       }
+
        card->ioport = sdio_readb(func, IF_SDIO_IOPORT, &ret);
        if (ret)
                goto release_int;