wl1251: fix ELP_CTRL register reads
[pandora-wifi.git] / drivers / net / wireless / wl12xx / wl1251_sdio.c
index d234285..0228e97 100644 (file)
 #define SDIO_DEVICE_ID_TI_WL1251       0x9066
 #endif
 
 #define SDIO_DEVICE_ID_TI_WL1251       0x9066
 #endif
 
+struct wl1251_sdio {
+       struct sdio_func *func;
+       u32 elp_val;
+};
+
 static struct wl12xx_platform_data *wl12xx_board_data;
 
 static struct sdio_func *wl_to_func(struct wl1251 *wl)
 {
 static struct wl12xx_platform_data *wl12xx_board_data;
 
 static struct sdio_func *wl_to_func(struct wl1251 *wl)
 {
-       return wl->if_priv;
+       struct wl1251_sdio *wl_sdio = wl->if_priv;
+       return wl_sdio->func;
 }
 
 static void wl1251_sdio_interrupt(struct sdio_func *func)
 }
 
 static void wl1251_sdio_interrupt(struct sdio_func *func)
@@ -90,10 +96,17 @@ static void wl1251_sdio_write(struct wl1251 *wl, int addr,
 static void wl1251_sdio_read_elp(struct wl1251 *wl, int addr, u32 *val)
 {
        int ret = 0;
 static void wl1251_sdio_read_elp(struct wl1251 *wl, int addr, u32 *val)
 {
        int ret = 0;
-       struct sdio_func *func = wl_to_func(wl);
-
+       struct wl1251_sdio *wl_sdio = wl->if_priv;
+       struct sdio_func *func = wl_sdio->func;
+
+       /*
+        * The hardware only supports RAW (read after write) access for
+        * reading, regular sdio_readb won't work here (it interprets
+        * the unused bits of CMD52 as write data even if we send read
+        * request).
+        */
        sdio_claim_host(func);
        sdio_claim_host(func);
-       *val = sdio_readb(func, addr, &ret);
+       *val = sdio_readb_ext(func, addr, &ret, wl_sdio->elp_val);
        sdio_release_host(func);
 
        if (ret)
        sdio_release_host(func);
 
        if (ret)
@@ -103,7 +116,8 @@ static void wl1251_sdio_read_elp(struct wl1251 *wl, int addr, u32 *val)
 static void wl1251_sdio_write_elp(struct wl1251 *wl, int addr, u32 val)
 {
        int ret = 0;
 static void wl1251_sdio_write_elp(struct wl1251 *wl, int addr, u32 val)
 {
        int ret = 0;
-       struct sdio_func *func = wl_to_func(wl);
+       struct wl1251_sdio *wl_sdio = wl->if_priv;
+       struct sdio_func *func = wl_sdio->func;
 
        sdio_claim_host(func);
        sdio_writeb(func, val, addr, &ret);
 
        sdio_claim_host(func);
        sdio_writeb(func, val, addr, &ret);
@@ -111,10 +125,26 @@ static void wl1251_sdio_write_elp(struct wl1251 *wl, int addr, u32 val)
 
        if (ret)
                wl1251_error("sdio_writeb failed (%d)", ret);
 
        if (ret)
                wl1251_error("sdio_writeb failed (%d)", ret);
+       else
+               wl_sdio->elp_val = val;
 }
 
 static void wl1251_sdio_reset(struct wl1251 *wl)
 {
 }
 
 static void wl1251_sdio_reset(struct wl1251 *wl)
 {
+       extern int sdio_reset_comm(struct mmc_card *card);
+       struct sdio_func *func = wl_to_func(wl);
+       int ret;
+
+       sdio_claim_host(func);
+       sdio_reset_comm(func->card);
+       ret = sdio_enable_func(func);
+       if (ret)
+               goto release;
+
+       sdio_set_block_size(func, 512);
+
+release:
+       sdio_release_host(func);
 }
 
 static void wl1251_sdio_enable_irq(struct wl1251 *wl)
 }
 
 static void wl1251_sdio_enable_irq(struct wl1251 *wl)
@@ -197,6 +227,7 @@ static int wl1251_sdio_probe(struct sdio_func *func,
        int ret;
        struct wl1251 *wl;
        struct ieee80211_hw *hw;
        int ret;
        struct wl1251 *wl;
        struct ieee80211_hw *hw;
+       struct wl1251_sdio *wl_sdio;
 
        hw = wl1251_alloc_hw();
        if (IS_ERR(hw))
 
        hw = wl1251_alloc_hw();
        if (IS_ERR(hw))
@@ -204,6 +235,12 @@ static int wl1251_sdio_probe(struct sdio_func *func,
 
        wl = hw->priv;
 
 
        wl = hw->priv;
 
+       wl_sdio = kzalloc(sizeof(*wl_sdio), GFP_KERNEL);
+       if (wl_sdio == NULL) {
+               ret = -ENOMEM;
+               goto out_free_hw;
+       }
+
        sdio_claim_host(func);
        ret = sdio_enable_func(func);
        if (ret)
        sdio_claim_host(func);
        ret = sdio_enable_func(func);
        if (ret)
@@ -213,7 +250,8 @@ static int wl1251_sdio_probe(struct sdio_func *func,
        sdio_release_host(func);
 
        SET_IEEE80211_DEV(hw, &func->dev);
        sdio_release_host(func);
 
        SET_IEEE80211_DEV(hw, &func->dev);
-       wl->if_priv = func;
+       wl_sdio->func = func;
+       wl->if_priv = wl_sdio;
        wl->if_ops = &wl1251_sdio_ops;
        wl->set_power = wl1251_sdio_set_power;
 
        wl->if_ops = &wl1251_sdio_ops;
        wl->set_power = wl1251_sdio_set_power;
 
@@ -248,6 +286,9 @@ static int wl1251_sdio_probe(struct sdio_func *func,
        if (ret)
                goto out_free_irq;
 
        if (ret)
                goto out_free_irq;
 
+       /* we can power it down now until it's started */
+       wl->set_power(0);
+
        sdio_set_drvdata(func, wl);
        return ret;
 
        sdio_set_drvdata(func, wl);
        return ret;
 
@@ -259,15 +300,20 @@ disable:
        sdio_disable_func(func);
 release:
        sdio_release_host(func);
        sdio_disable_func(func);
 release:
        sdio_release_host(func);
+       kfree(wl_sdio);
+out_free_hw:
+       wl1251_free_hw(wl);
        return ret;
 }
 
 static void __devexit wl1251_sdio_remove(struct sdio_func *func)
 {
        struct wl1251 *wl = sdio_get_drvdata(func);
        return ret;
 }
 
 static void __devexit wl1251_sdio_remove(struct sdio_func *func)
 {
        struct wl1251 *wl = sdio_get_drvdata(func);
+       struct wl1251_sdio *wl_sdio = wl->if_priv;
 
        if (wl->irq)
                free_irq(wl->irq, wl);
 
        if (wl->irq)
                free_irq(wl->irq, wl);
+       kfree(wl_sdio);
        wl1251_free_hw(wl);
 
        sdio_claim_host(func);
        wl1251_free_hw(wl);
 
        sdio_claim_host(func);